Answer the second question:
If your TakeFoo function is intended to call non const members of Foo, use
int TakeFoo (Foo& FooBar);
If you are sure that TakeFoo only accepts rvalue as an argument, use
int TakeFoo (Foo&& FooBar);
If you want to make some changes to Foo to calculate the return value of int , use
int TakeFoo (const Foo& FooBar) { Foo FooBar MyFooBar = FooBar; // do something with MyFooBar and return int }
Or
int TakeFoo (Foo FooBar);
Answer your first question:
int TakeFoo (FooBar) should not change FooBar to calculate the result of int . The best design would be
Foo transform_foo(Foo const& foo); int compute_result(Foo const& foo); int TakeFoo(Foo const& FooBar) { return compute_result( transform_foo(FooBar) ); }
source share