I am learning C++. In the course I am doing, we have now covered the section about classes.
I now know that functions can be overloaded; given different types of parameters, a different implementation can be made. However, in the case of member functions, the caller sort of also becomes part of the function. Is there any way we can use function overloading to pick an appropriate implementation depending on if the caller object is const or not? Or if it is an lvalue vs an rvalue?
So if there is a class Foo
, is there a way to have different implementations of myFoo.bar()
depending on if myFoo
is const, or if you pass it an rvalue such as in the case of Foo{}.bar()
?