C++ examples for Class:Constructor
Constructing multiple objects, invokes a constructor on an array of objects
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class Employee{//from w w w. j av a2s . com public: Employee(){ cout << "constructing employee" << endl; workHour = 0; salary = 0.0; } protected: int workHour; double salary; }; int main(int nNumberofArgs, char* pszArgs[]) { cout << "Creating an array of 5 Employee objects" << endl; Employee s[5]; return 0; }