C++ examples for Class:object
Construct an array of objects
#include <cstdio> #include <cstdlib> #include <iostream> #include <string.h> using namespace std; class Employee/* ww w . j a va 2 s.c om*/ { public: Employee(const char *pName) { cout << "constructing freshman " << pName << endl; name = pName; workHour = 0; salary = 0; } Employee(const char *pName, int xfrHours,double xSalary) { cout << "constructing transfer " << pName << endl; name = pName; workHour = xfrHours; salary = xSalary; } protected: string name; int workHour; double salary; }; int main(int argcs, char* pArgs[]) { Employee s[]{"H", "P"}; Employee t[]{{"J", 0, 0.0}, {"S", 12, 2.5}}; return 0; }