Jecho

导航

C2106: '=' : left operand must be l-value

class PPerson
{
public:
PPerson(int age){_age = age;}

PPerson(){}

inline int& GetAge()
{
return _age;
}

int _age;
};

class ClassTest
{
public:
ClassTest(void);

ClassTest(int id)
{
_person = PPerson(100);
_Id = id;
}

~ClassTest(void);

inline void IlineTest()
{

}

inline int GetId() const
{
return _Id;
}

inline PPerson GetPerson()
{
_person = PPerson(100);
return _person;
}

private:

PPerson _person;
int _Id;
};

 

(ct.GetPerson()._age) = 100; // Error 1 error C2106: '=' :  left operand must be l-value // return a r-value

 (ct.GetPerson().GetAge()) = 100; // No Error // return a l-value because of the &

posted on 2013-05-23 13:24  Jecho  阅读(669)  评论(0)    收藏  举报