0

In the code below, is sstill 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()
Midnight Exigent
  • 615
  • 4
  • 15

0 Answers0