为什么不能在块中声明静态成员?

时间:2017-06-29 20:13:30

标签: c++

以下是一些代码:

class aclass {
  int x = 1; 
  static float peanut; //definition not allowed here or in any other class
};

float aclass::peanut = 5.2; //definition seems to only be allowed at file scope

int main() {
  //definition of peanut not allowed here
  return 0;
}

那么为什么不允许在块中定义peanut,例如函数或类?

0 个答案:

没有答案