How to create a simple class object in C++ programming stage 1

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Creating and tracking the class execution (constructor and destructor) order in C++ programming stage 1

To show: How to create and use a simple class in C++ programming, stage 1

 

// creating a simple C++ class, step 1

#include <iostream>

using namespace std;

 

// class, declaration

class line

{

public:

line(void);

~line(void);

};

 

// class implementation

line::line(void)

{

cout<<"Hai! I'm in line() constructor, I'm constructing your object!"<<endl;

}

line::~line(void)

{

cout<<"Hai! I'm in ~line() destructor, I'm destroying your object!"<<endl;

}

 

// main program

int main(void)

{

line LineOne;

 

cout<<"Hai! I'm in main() starting your program execution"<<endl;

cout<<"Just a program skeleton..."<<endl;

 

return 0;

}

 

Output example:

 

Hai! I'm in line() constructor, I'm constructing your object!

Hai! I'm in main() starting your program execution

Just a program skeleton...

Hai! I'm in ~line() destructor, I'm destroying your object!

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index