K
Kaspar Minosiants
Hi ,
there is a question about work of const_cast
The question is why the object is still reachable after a delete operation
class A {
int var;
public:
A():var(0){}
~A(){}
void setVar(int a){var=a;}
int getVar() const {return var;}
int getVar() {return var;}
};
int main() {
const A* a=new A();
A *b=const_cast<A*>(a);
delete a;
b->setVar(10);
cout<<b->getVar();
return 0;
}
there is a question about work of const_cast
The question is why the object is still reachable after a delete operation
class A {
int var;
public:
A():var(0){}
~A(){}
void setVar(int a){var=a;}
int getVar() const {return var;}
int getVar() {return var;}
};
int main() {
const A* a=new A();
A *b=const_cast<A*>(a);
delete a;
b->setVar(10);
cout<<b->getVar();
return 0;
}