I have a class Foo
.
I want a function, TakeFoo
, that accepts a Foo
object and calls methods on it. This is what I started with:
void TakeFoo (const Foo&);
However, I also need to be able to call non-const methods on it. So I change it to this:
void TakeFoo (Foo&);
However, this causes warnings when I try to pass a temporary to it. So I create an overload:
void TakeFoo (Foo&&);
However, I want to reuse code, so TakeFoo(Foo&&)
basically does this:
void TakeFoo (Foo&& FooBar)
{
TakeFoo(FooBar);
}
Why is this not causing a warning as well, because I am still taking a non-const reference to a temporary?