operator =? [英] operator= ?
本文介绍了operator =?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在我的班级中有一个方法,它将从
右侧设置一个std :: string
ie的值。 。
myClass c;
std :: string x(" Hello");
c = x;
我必须在myclass中实现什么方法来执行此操作?
解决方案
AFAIK,>
void myClass :: operator =(std :: string& str);
哎呀......应该是:
myClass& myClass :: operator =(std :: string& str)
Cat写道:哎呀......应该是:
myClass& myClass :: operator =(std :: string& str)
或者更好,
myClass& myClass :: operator =(const std :: string& str);
我认为OP不需要修改str。
I want to have a method in my class that will set its value from a
right hand side thats a std::string
ie..
myClass c;
std::string x("Hello");
c = x;
what method must I implement in myclass to do this?
解决方案
AFAIK,
void myClass::operator=(std::string& str);
Whoops.. that should probably be:
myClass& myClass::operator=(std::string& str)
Cat wrote:Whoops.. that should probably be:
myClass& myClass::operator=(std::string& str)
Or better yet,
myClass& myClass::operator=(const std::string& str);
As I assume the OP does not need to modify str.
这篇关于operator =?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文