Hi every body, i have a problem with r-value reference and l-value reference issue. i write this sample code
class MemoryBlock
{
public:
MemoryBlock(){};
MemoryBlock(int a){};
};
void g(const MemoryBlock&)
{
cout << "l-value " << endl;
}
void g(MemoryBlock&&)
{
cout << "r-value" << endl;
}
void fn(MemoryBlock&& block)
{
g(block);
}
int main()
{
fn(MemoryBlock());
fn(5);
}
i get following output:
l-value
r-value
i think that compiler treats a named rvalue reference as an lvalue and an unnamed rvalue reference as an rvalue. So in both calling modes, the unnamed parameter passed to fn, so why do we have a different response?
what is difference between two constructor of MemoryBlock class?