需要对Qt :: operator进行一些解释

时间:2011-04-20 07:31:52

标签: qt operator-overloading

我是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;
}

如果有人可以解释这究竟是什么以及为什么它在代码中会有很大的帮助。

谢谢你们。

〜Tharanga

2 个答案:

答案 0 :(得分:1)

他是overloading the assignment operator。这样,当他说

c2 = c1;

c2.dc1.d相同。

不具体Qt。另请参阅此long explanation

答案 1 :(得分:1)

此运算符是assignment operator。在你写的时候使用它:

Contact c1;
Contact c2;
c2 = c1;

在您的情况下,赋值运算符仅复制联系人的d成员,因此c2.d将与c1.d

相同