+ 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"; }

12th May 2018, 9:34 AM
Shahil Ahmed
Shahil Ahmed - avatar
3 Respuestas
+ 11
Use pointers or put it in its own block { } https://code.sololearn.com/cI6S9n9YBIMp/?ref=app
12th May 2018, 10:33 AM
jay
jay - avatar
+ 5
I want to destroy the obj at the lines before the other codes executes how to do that???
12th May 2018, 9:34 AM
Shahil Ahmed
Shahil Ahmed - avatar
+ 3
Thanks
12th May 2018, 1:06 PM
Shahil Ahmed
Shahil Ahmed - avatar