why when I try to compile this
I get:Code:test& operator~ (const test& b1, const test& b2);
error: âtest& Htest:perator~(const test&, const test&)â must take âvoidâ
why when I try to compile this
I get:Code:test& operator~ (const test& b1, const test& b2);
error: âtest& Htest:perator~(const test&, const test&)â must take âvoidâ
operator~ is a unary operator. Therefore, if it is overloaded as a member function, it must have take no arguments. If it is overloaded as a free function, it must take exactly one argument.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
and does it return a test& or a test? a reference or a value?
Most likely it would return by value. (But of course there are exceptions for exceptional semantics.)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
how about this one:
I get this error:Code:type& operator~=();
:35: error: expected primary-expression before â)â token
:35: error: declaration of âoperator~â as non-function
operator~= is a binary function.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
so it should take two arguments you mean?
You cannot overload ~= because it's not a valid operator in C++. You can only overload (most of) the operators that already come with the language.
Yes, that is correct.Originally Posted by Ronix
By the way, -EquinoX-, I really suggest that you post the smallest and simplest program that demonstrates the error.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)