I want my function to take a lvalue reference and absolutely not a rvalue or temporary or whatever.
This is my function:
template<class T> void foo(T& value) {} // Imagine I have a class Foo struct Foo { int a; int b; }; When I call foo(Foo{1, 2}), first, it compiles even if I asked for a lvalue reference, and second, it doesn't work because foo stores the address of the passed value, so I get garbage when I read it later.
How to force foo to take a lvalue reference?
foo(Foo(1, 2))does not compile.warning C4239: nonstandard extension used: 'argument': conversion from 'Foo' to 'T &'or anerror C2664: 'void foo<Foo>(T &)': cannot convert argument 1 from 'Foo' to 'T &', depending on if languages extensions are enabled or disabled.