mfc 重载赋值运算符

重载赋值运算符=


 一、重载运算符格式
   返回类型     operator 运算符 (参数);
   如:
    bool  operator=(char*s);
   int    operator>(char*s);
   bool  operator new(int size);
 二、重载赋值运算符=
//头文件 Message.h  
int operator=(char *s);
//源文件 Message.cpp 

int CMessage::operator=(char *s)
{
    delete[] msg;
    printf("构造this=%x
",this);
    //分配空间
    msg=new char[256];
    //实现复制功能
    strcpy_s(msg,256,s);
    return 1;
}
 三、重载注意事项
  以下运算符不能重载
   作用域解析符             ::
   条件运算符               ?:
   直接成员访问运算符       .
   sizeof运算符              sizeof
   对指向类成员的指针解除引用的运算符 .*
原文地址:https://www.cnblogs.com/whzym111/p/6182165.html