在下面给出的代码中,我cout在所有类构造函数、析构函数和重载赋值运算符中编写了语句。
#include <iostream>
using namespace std;
class person {
string name;
int age ;
int id ;
static int num;
public :
person (string name , int age) : name(name) , age(age) {
id = num++;
cout << "creating person : " << id << "(" << name <<")"<< endl;
}
person (const person &other) : name(other.name) , age(other.age) {
id = num++;
cout << "CREATING PERSON : " << id << "(" << name <<")" << " …Run Code Online (Sandbox Code Playgroud)