I
Immortal Nephi
I try to write operator= and operator+ in class. The bult-in data
type will report "warning C4552: '+' : operator has no effect;
expected operator with side-effect" if my code shows this below.
int main()
{
int x = 0;
x + 1; // no effect
}
The C++ Compiler reports warning message. It is correct because I
should not write "x + 1;" However you will see user-defined type like
this below. I do not want "t + t2;". How can C++ Compiler report
error message? "t = t + t2;" and "t += t2" are acceptable.
class test
{
public:
test() {}
~test() {}
test& operator=( const test &r )
{
return *this;
}
test& operator+( const test &r )
{
return *this;
}
};
int main()
{
test t, t2;
t + t2; // ???
t = t + t2;
return 0;
}
type will report "warning C4552: '+' : operator has no effect;
expected operator with side-effect" if my code shows this below.
int main()
{
int x = 0;
x + 1; // no effect
}
The C++ Compiler reports warning message. It is correct because I
should not write "x + 1;" However you will see user-defined type like
this below. I do not want "t + t2;". How can C++ Compiler report
error message? "t = t + t2;" and "t += t2" are acceptable.
class test
{
public:
test() {}
~test() {}
test& operator=( const test &r )
{
return *this;
}
test& operator+( const test &r )
{
return *this;
}
};
int main()
{
test t, t2;
t + t2; // ???
t = t + t2;
return 0;
}