F
Felix Sima
Hi.
Does the following line generate a memory leak or doesn't ?
*** foo( new CTest( ) ); *** //See code below.
Watching the output of the program seems that only the constructor
of the temporary object is called so that the memory allocated for
"new CTest( )" doesn't get deallocated.
Is it the right behaviour? If not, what can I do ?
Thank you.
Felix
********* CODE *********
#include <iostream>
using namespace std;
class CTest
{
public:
CTest()
{
cout << "Constructor" << endl;
};
~CTest()
{
cout << "Destructor" << endl;
};
};
void foo( CTest *p )
{
};
int main( int argc, char **argv )
{
foo( new CTest( ) ); //Memory leak here ?
return 0;
};
******** OUTPUT ************
Constructor
Does the following line generate a memory leak or doesn't ?
*** foo( new CTest( ) ); *** //See code below.
Watching the output of the program seems that only the constructor
of the temporary object is called so that the memory allocated for
"new CTest( )" doesn't get deallocated.
Is it the right behaviour? If not, what can I do ?
Thank you.
Felix
********* CODE *********
#include <iostream>
using namespace std;
class CTest
{
public:
CTest()
{
cout << "Constructor" << endl;
};
~CTest()
{
cout << "Destructor" << endl;
};
};
void foo( CTest *p )
{
};
int main( int argc, char **argv )
{
foo( new CTest( ) ); //Memory leak here ?
return 0;
};
******** OUTPUT ************
Constructor