需要一些关于 Qt::operator 的解释
我是 Qt 的大佬,参考了一些关于隐式和显式共享的教程,我发现了下面的文章。
http://cdumez.blogspot.com/2011 /03/implicit-explicit-data-sharing-with-qt.html
在代码部分我无法理解以下运算符的功能
Contact& Contact::operator=(const Contact& other) {
d = other.d;
return *this;
}
如果有人可以解释这到底是什么确实以及为什么它存在于代码中,这将是一个很大的帮助。
谢谢你们。
〜塔兰加
I am a biginer to Qt and referring to some tutorials on implicit ans explicit sharing and I came across following article.
http://cdumez.blogspot.com/2011/03/implicit-explicit-data-sharing-with-qt.html
in the code section I was not able to understand the functionality of the following operator
Contact& Contact::operator=(const Contact& other) {
d = other.d;
return *this;
}
If some one could explain this what exactly this does and why it is there for in code it would be a great help.
Thanks guys.
~Tharanga
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他重载了赋值运算符。这样,当他说
c2.d
时,将与c1.d
相同。它不是
Qt
特定的。另请参阅此长解释。He is overloading the assignment operator. That way, when he says
c2.d
will be the same asc1.d
.It is not
Qt
specific. Also see this long explanation.此运算符是赋值运算符。当您编写时使用它:
在您的情况下,赋值运算符仅复制 contact 的 d 成员,因此
c2.d
将与c1.d
相同This operator is the assignment operator. It is used when you write:
In your case the assignment operator only copies the d member of contact so
c2.d
will be the same asc1.d