In the code below, is s
still pointing to valid memory after s1 is destroyed ? If yes, how does that work ? If no, anything we can do to avoid it ?
#include <iostream>
struct S {
S(){std::cout<<"S()\n";}
~S(){std::cout<<"~S()\n";}
};
int main(){
S *s;
{
S s1;
s=&s1;
}
}
//output:
//S()
//~S()