titanandrews
Programmer
Hi,
This should be a simple enough question for the C++ veterans...
If I have a function that returns something, how do I know when I should return a pointer (*) to the object or the address (&). It seems like most of the code I have seen in books when returning a string, they return the address of. But, if I return the address of let's say a list<string>, compiler gives me a warning saying "warning C4172: returning address of local variable or temporary" Now this does make sense, because I believe that once the block (function) has exited the destructor will get called on the local object which means that whoever gets the address of this object is not going to like it. What doesn't make sense to me is why the compiler does not complain about returning address of string object.
I appreciate your help!
thanks,
Barry
This should be a simple enough question for the C++ veterans...
If I have a function that returns something, how do I know when I should return a pointer (*) to the object or the address (&). It seems like most of the code I have seen in books when returning a string, they return the address of. But, if I return the address of let's say a list<string>, compiler gives me a warning saying "warning C4172: returning address of local variable or temporary" Now this does make sense, because I believe that once the block (function) has exited the destructor will get called on the local object which means that whoever gets the address of this object is not going to like it. What doesn't make sense to me is why the compiler does not complain about returning address of string object.
I appreciate your help!
thanks,
Barry