$ g++ main.cpp --std=c++11
main.cpp:10:49: error: ‘Foo Foo::operator*(const Foo&, const Foo&)’ must take either zero or one argument
Foo operator*(const Foo &lhs, const Foo &rhs)
^
main.cpp: In function ‘int main()’:
main.cpp:20:8: error: no match for ‘operator*’ (operand types are ‘Foo’ and ‘Foo’)
(a * b) = c;
Is your code an example code? Your overloaded operator is wrong. Is the format wrong? Shouldn’t the overloaded be as follows?
We cannot simply understand "lvalue" and "rvalue" as appearing on both sides of the equal sign. Especially when a class object appears on the left side of the equal sign, the object assignment is actually completed by calling the function operator=:
There is a problem with your Code, it’s mine.
Is your code an example code? Your overloaded operator is wrong. Is the format wrong? Shouldn’t the overloaded be as follows?
I don’t quite understand what you mean.
I remember that rvalues can also be assigned.What if the rvalue returned by the function is a reference?
Just like the following code
We cannot simply understand "lvalue" and "rvalue" as appearing on both sides of the equal sign. Especially when a class object appears on the left side of the equal sign, the object assignment is actually completed by calling the function
operator=
:(a * b) = c
==>(a*b).operator=(c)