I am wondering what the standard says about the following code snippet. Is it possible to execute a string destructor of a temporary object before calling printPointer ?
ps The VS2010 compiler does not complain about this code and works correctly.
void printPointer(const string* pointer) { cout << *pointer << endl; } const string* func(const string& s1) { return &s1; } int main() { printPointer(func("Hello, World!!!")); }
c ++ language-lawyer destructor temporary object-lifetime
skap
source share