Thursday, March 17, 2011

Cpp Constructor

# include "iostream"
using namespace std;

class Application
{
public:

int nDataInformation;
public:
void fnApplication()
{

cout << nDataInformation << endl;
}

Application();//default constructor
Application(int);//Second constructor
~Application();//Destructor

}Object;

Application::Application()
{
nDataInformation = 1000;
}

Application::Application(int ndata)
{
cout << ndata<< endl;
}

Application::~Application()
{
nDataInformation = 0;
cout << "I am in Destructor \n";

}


void main()
{
Application *Constructor=NULL;// Constructor Varible intialization
Constructor = new Application();
Object.fnApplication();//Member function calling
Application Application(9999);//Second constructor with argument


}

OUTPUT:

1000
9999
I am in Destructor
I am in Destructor
Press any key to continue . . .

No comments:

Post a Comment