34 lines
533 B
Plaintext
34 lines
533 B
Plaintext
Where a set of operators is overloaded, it is important that the interactions between the operators meet developer expectations.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
class A
|
|
{
|
|
public:
|
|
A& operator= ( A const & rhs );
|
|
};
|
|
|
|
A & operator += ( A const & lhs, A const & rhs );
|
|
A const operator + ( A const & lhs, A const & rhs ) // Noncompliant
|
|
{
|
|
return lht -= rhs;
|
|
}
|
|
void f ( A a1, A a2 )
|
|
{
|
|
A x;
|
|
x = a1 + a2;
|
|
a1 += a2;
|
|
if ( x == a1 ) // This should be true, but it's not
|
|
{
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* MISRA {cpp}:2008, 5-17-1
|
|
|