【发布时间】:2014-09-11 20:41:45
【问题描述】:
FooClass.h:
class FooClass {
.
.
.
private:
World *myWorld;
const Player *&player;
.
.
.
}
FooClass.cpp:
FooClass::FooClass(..., World *w) : myWorld(w), player(w->getPlayer())
{
.
.
.
}
这会触发以下错误:Non-const lvalue reference to type 'const Player *' cannot bind to a temporary of type 'Player *'。然而const Player * 类型的左值显然是一个 const 左值...
【问题讨论】:
-
const Player *是一种类型,而不是左值。无论w->getPlayer()返回的是Player *。
标签: c++ pointers reference constants lvalue