的像这样的代码:无效使用非静态数据成员
class foo {
protected:
int a;
public:
class bar {
public:
int getA() {return a;} // ERROR
};
foo()
: a (p->param)
};
我得到这个错误:
invalid use of non-static data member 'foo::a'
目前的变量a
中的foo
构造函数初始化。
,如果我让静态的,那么它说:
error: 'int foo::a' is a static data member; it can only be initialized at its definition
但是我想在构造函数的值传递给a
。 然后是什么解决方案?
为什么不移动getA()到foo? – Eduardo 2012-03-06 19:18:16
你的问题中的代码有几个问题,使它不清楚你真的想做什么。请编辑你的问题,以表明你的总体目标是什么。 – 2012-03-06 19:32:42