定义:
Human& operator=(const Human& other);
实现:
Human& Human::operator=(const Human& other){
//当other = other时;
if (this == &other) return *this;
//假如 f1 = f2;
//自动调用, f1.operator=(f2)
this->name = other.name;
this->age = other.age;
this->sex = other.sex;
strcpy_s(this->addr,ADDR_LEN, other.addr);
//返回对象的引用,是为了做链式处理: f1 = f2 = f3;
return *this;
}
调用:
对象赋值时自动调用
//调用赋值构造函数
lisi = zhangsan;
Human.h
#pragma once
#include
#include
#include
using namespace std;
cla