这是头文件:employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee(const string &first, const string &last)
Run Code Online (Sandbox Code Playgroud)
重载的构造函数
: firstName(first),
Run Code Online (Sandbox Code Playgroud)
firstName重载的构造函数
lastName(last)
Run Code Online (Sandbox Code Playgroud)
lastName重载的构造函数
{ //The constructor start
++counter;
Run Code Online (Sandbox Code Playgroud)
它为每个创建的对象增加一个加号;
cout << "Employee constructor for " << firstName
<< ' ' << lastName << " called." << endl;
}
~Employee() {
Run Code Online (Sandbox Code Playgroud)
析构函数cout <<"~Workee()调用"<< firstName <<"<< lastName << endl;
返回每个对象的名和姓
--counter;
Run Code Online (Sandbox Code Playgroud)
反减一
}
string getFirstName() const {
return firstName;
}
string getLastName() const {
return lastName;
} …Run Code Online (Sandbox Code Playgroud)