I have a question regarding pointers to pointers.
Lets assume I have a class foo
. And I create a pointer of a pointer to this class somewhere in my code.
foo** x;
What would be the return value if I make a function which returns foo**
as well?
foo** bar();
I also have an array of pointers and I want to return this array in an accessor function as a pointer-to-pointer-to a class.
I'm not sure the question is about shared names or double pointers, but if such is possible, you can declare allocate space for a foo object and return that address/pointer(variable).
Does it really have to be a double pointer though? You can make a pointer to an allocated pointer, but that would have no point. On the other hand, you can allocate an array and return it's address to have a double pointer.
That's all I can tell :/
What would be the return value if I make a foo** foo(); function?
It would be the address of an object of type foo*
(or a pointer-interconverible type). Or it could be null, or an invalid pointer value (but you should avoid the latter).
Note that calling this a "double pointer" is confusing since double is a type, so one might understand that you meant double*
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.