Hi all,
I have written a code which will create object on runtime using new and will destroy it using delete , I want to show that while doing so it calls the constructor and the destructor of the class but I am getting build error for my class
#include<iostream>
#include<new>
usingnamespace std;
class trynd
{
int i
public :
trynd()
{
cout <<"I am in constructor"<<endl;
}
void print()
{
coout << i <<endl;
}
~ trynd()
{
cout <<"I am in destructor"<<endl;
}
};
int main()
{
{
trynd * nd = new trynd;
delete nd;
}
system("pause");
return 0;
}
the error is : [Build Error] [new&delete.o]Error1
What is the problem?
Executes correctly for me using Visual Studio after correcting the two errors Chervil pointed out.
Note: It is not necessary to include the <new> header. The new header defines versions of new and delete in the global namespace in addition to the versions in the std namespace.