+ 5
How to destroy a object independently?
#include <iostream> using namespace std; class MyClass{ MyClass(){ cout<<"Obj constructed\n"; } ~MyClass(){ cout<<"Obj destructed\n"; }}; int main(){ MyClass Obj; //I want to delete my Obj here how to do that? cout<<"\nHello world"; cout<<"Other codes"; cout<<"stuffs\n"; }
3 ответов
+ 11
Use pointers or put it in its own block { }
https://code.sololearn.com/cI6S9n9YBIMp/?ref=app
+ 5
I want to destroy the obj at the lines before the other codes executes how to do that???
+ 3
Thanks