重载指针对象
你好 如何重载指针对象。我试过了,不行。谁能帮助我。
CMyClass *InstancePtr = new CMyClass;
Myclassptr = MapObject->second; // returns *CMyclass
//overlaod Assignment operator ...
InstancePtr = Myclassptr;
//////////////////////////////////////////////////////
CMyClass * CMyClass::operator=(const CMyClass *ptr)
{
//some operation
int x = 4;
x = x - 2;
return this;
}
Hi
how do I overload pointer objects . I tried it doesnt work out . can anyone help me.
CMyClass *InstancePtr = new CMyClass;
Myclassptr = MapObject->second; // returns *CMyclass
//overlaod Assignment operator ...
InstancePtr = Myclassptr;
//////////////////////////////////////////////////////
CMyClass * CMyClass::operator=(const CMyClass *ptr)
{
//some operation
int x = 4;
x = x - 2;
return this;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不能重载指针类型对象的运算符。
您只能重载至少一个操作数为类类型或枚举类型的运算符。
由于重载的赋值运算符必须实现为非静态成员函数,因此只能在左侧操作数为类类型的情况下重载。
You cannot overload operators for pointer type objects.
You can only overload an operator where at least one of the operands is of class type or enum type.
Since an overloaded assignment operator must be implemented as a non-static member function, it can only be overloaded where the left-hand side operand is of class type.