重载赋值运算符

iamlookingforyou 22 0 PDF 2021-02-01 17:02:30

赋值运算符重载用于对象数据的复制 operator= 必须重载为成员函数 重载函数原型为: 类型 & 类名 :: operator= ( const 类名 & ) ; 案例:完善Name类,支持=号操作。 具体看如下代码: #define _CRT_SECURE_NO_WARNINGS #include using namespace std; class Name { public: Name(const char* myp) { m_len = strlen(myp); m_p = (char*)malloc(m_len+1);

用户评论
请输入评论内容
评分:
暂无评论