Constructing a single object with constructor - C++ Class

C++ examples for Class:Constructor

Description

Constructing a single object with constructor

Demo Code

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

class Employee// w ww  .j  av a2s.  c  om
{
  public:
    Employee()
    {
        cout << "constructing employee" << endl;
        workHour = 0;
        salary = 0.0;
    }
  protected:
    int  workHour;
    double salary;
};

int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "Creating a new Employee object" << endl;
    Employee s;

    cout << "Creating a new object off the heap" << endl;
    Employee* pS = new Employee;

    return 0;
}

Result


Related Tutorials