0
class Cls {
public:
Cls() {
}

Cls(int id)
: id(id)  {

}

~Cls() {
  id = 999;
  std::cout<<id<<" Bye!"<<std::endl;
}

int id;
char data[999999] = {0, };
};

int main() {
    Cls* cl3 = new Test(3);
    int* id = &(cl3->id);
    std::cout<<id<<std::endl;
    std::cout<<*id<<std::endl;
    delete cl3;
    std::cout<<id<<std::endl;
    std::cout<<*id<<std::endl;
    return 0;
}

Why id is still accessible after t3 class is deleted? To my knowledge, the destructor will delete all member variables.

asdasdtt3
  • 1
  • 1

0 Answers0