samedi 21 février 2015

The member variable of a lvalue object is rvalue?

I found that the member variable of a lvalue object is recognized as rvalue, I am wondering why. Here is my example:



struct CAT
{
CAT(){}
int age_;
};


void f(int&& )
{
cout<<"f(int&&)"<<endl;
}

void f(int &)
{

cout<<"f(int&)"<<endl;
}


template<typename T>
void foo(T&& t)
{
f(std::forward<int>(t.age_));
}


int main()
{
CAT c;
foo(c); //c is lvalue
foo(std::move(c)); //move(c) is rvalue
}


output:



f(int&&)
f(int&&)


I have test it using clang3.6 and gcc 4.8.2.


Aucun commentaire:

Enregistrer un commentaire