c++ - General Pointer issue -
i've tried following:
std::string* member::getname() { std::string name2 = "sdfsdfsd"; homecoming &name2; } std::string* name; fellow member m; name = m.getname(); std::cout << *name << std::endl;
and "works", shouldn't name2 unavailable after getname() called? , pointer points nothing?
taking address of local stack variable , using when it's no longer in scope it's undefined behavior.
as "it works", doesn't mean work or reliable practice. stack isn't wiped out when returning. take @ definition of "undefined behavior"
c++ pointers
No comments:
Post a Comment