Hi All,
I just read an instereing article and want to test if there is a memory leak for the following code. The code is following:
[code=cpp]
#include <iostream>
using namespace std;
class A{
public:
A() { cout << " Constructor!\n" ; }
~A() { cout << "Destructor!\n" ; }
};
int main() {
A * ptA = new A(* new A);
delete ptA;
return 0;
}
[/code]
The output is,
Constructor!
Destructor!
Should there be two objects created and destructed? Why only pari of output? Thanks.
Best,
Jason
I just read an instereing article and want to test if there is a memory leak for the following code. The code is following:
[code=cpp]
#include <iostream>
using namespace std;
class A{
public:
A() { cout << " Constructor!\n" ; }
~A() { cout << "Destructor!\n" ; }
};
int main() {
A * ptA = new A(* new A);
delete ptA;
return 0;
}
[/code]
The output is,
Constructor!
Destructor!
Should there be two objects created and destructed? Why only pari of output? Thanks.
Best,
Jason
Comment