0
Why this code is printing obj 2 times?.. How's it possible to call destructor by object in main function?
c++ #include <iostream> using namespace std ; class A{ public : ~A(){ cout <<"obj"; } } ; int main() { A obj; obj.~A(); return 0; } https://code.sololearn.com/cIhjsZ8EZPPP/?ref=app
3 Antworten
+ 1
Maybe something like here?
https://stackoverflow.com/questions/37690829/destructor-called-twice
0
The base class constructor and destructor are called when an object of the derived class is created or deleted.
That is, in this case it is enough:
int main(){
A obj;
}
0
Oh so the destructor is automatically called when the program ends
You called it manually creating the second obj.
Idk why there isn't a space tho