I am currently reading this tutorial/explanation of rvalue references:
http://thbecker.net/articles/rvalue_references/section_07.html
In the 2nd to last paragraph, the author mentions that "the argument of the copy constructor of T in the body of factory is an lvalue". The code he is referring to is this:
template<typename T, typename Arg>
shared_ptr<T> factory(Arg const & arg)
{
return shared_ptr<T>(new T(arg));
}
I realise that new T(arg)
constructs a T object on the heap, but isn't the returned value a temporary pointer value which will be lost if not used (leading to a memory leak I guess), and hence an rvalue?
EDIT: Just to clarify, I understand that there will be no memory leak in this example. I just meant that, if the pointer value would have not been used we would have no way of accessing the constructed T object and hence we'd get a memory leak.