Code
操作符应该是member function/nomember function
1.一元运算符是member
2.=,(),[],->必须是member
3.assignment版的运算符(+=,-=,/=,*=等)都必须是member function.
4.其他二元运算符都应该是nomember function
1 bool myclass::operator==(const myclass& rV)const
2 {
3 if(this->? == rV.?)
4 {
5 return true;
6 }
7 return false;
8 }
9 bool myclass::operator!=(const myclass& rV)const
10 {
11 return !(*this == rV);
12 }
13
14 myclass& myclass::operator+=(const myclass& rV)
15 {
16
17 return *this;
18 }
19
20 bool myclass::operator>(const myclass& rV)const
21 {
22 if (this->? > rV.?)
23 {
24 return true;
25 }
26 return false;
27 }
28
29 myclass& myclass::operator=(const myclass& rV)
30 {
31 this->? = rV.?;
32 return *this;
33 }
操作符应该是member function/nomember function
1.一元运算符是member
2.=,(),[],->必须是member
3.assignment版的运算符(+=,-=,/=,*=等)都必须是member function.
4.其他二元运算符都应该是nomember function
1 bool myclass::operator==(const myclass& rV)const
2 {
3 if(this->? == rV.?)
4 {
5 return true;
6 }
7 return false;
8 }
9 bool myclass::operator!=(const myclass& rV)const
10 {
11 return !(*this == rV);
12 }
13
14 myclass& myclass::operator+=(const myclass& rV)
15 {
16
17 return *this;
18 }
19
20 bool myclass::operator>(const myclass& rV)const
21 {
22 if (this->? > rV.?)
23 {
24 return true;
25 }
26 return false;
27 }
28
29 myclass& myclass::operator=(const myclass& rV)
30 {
31 this->? = rV.?;
32 return *this;
33 }