class Foo{};
class BarParent
{
Foo* p_foo;
public:
BarParent(Foo * const p_x) //OR BarParent(Foo const * x) OR BarParent(Foo * x)
//OR (Foo const * const x)
{
p_foo = x;
}
};
class BarChild: public BarParent
{
public:
BarChild(const Foo& x)
: BarParent(& x){}
};
我打算是:使用BarChild
構造函數時,點x
與p_foo
。有沒有辦法做到這一點。`const`ness,引用和函數調用
我已經試過BarParent
ctor沒有運氣的所有可能的簽名。
總結:出於某種原因,我被混淆的是分配(指針到非const
對象)至(指針const
對象)的事實打破const
限制。
你應該把'p_foo'一個'富常量*'。 –
你想用'p_foo'或'x'做什麼?如果你想修改它,你需要傳入一個非const指針。如果不是,你需要在我的應用程序中創建'p_foo'' const' – maditya
@AndyProwl它不是,並且可以通過其他函數更改 – aiao