格式
类名 &类名::operator=(const 类名 &源对象){if (this != &源对象){ // 目的对象与源对象不是同一个对象…… // 复制被被赋值对象}return *this; // 返回目的对象}
示例代码
CPerson(const CPerson &oCPerson) //拷贝构造函数{m_lpszName = new char[strlen( oCPerson.m_lpszName )+1];strcpy(m_lpszName, oCPerson.m_lpszName);m_lpszSex = new char[strlen( oCPerson.m_lpszSex )+1];strcpy(m_lpszSex, oCPerson.m_lpszSex);}
