相关疑难解决方法(0)

为什么C++ 11'auto'关键字不适用于静态成员?

class Foo {
 public:
  static const char *constant_string;
};

auto Foo::constant_string = "foo";

int main(void) {
};
Run Code Online (Sandbox Code Playgroud)

编译:gcc(Ubuntu/Linaro 4.6.3-1ubuntu5)4.6.3像这样:

gcc -std=c++0x ./foo.cc 
./foo.cc:6:11: error: conflicting declaration ‘auto Foo::constant_string’
./foo.cc:3:22: error: ‘Foo::constant_string’ has a previous declaration as ‘const char* Foo::constant_string’
./foo.cc:6:11: error: declaration of ‘const char* Foo::constant_string’ outside of class is not definition [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

这是auto关键字的预期行为,还是gcc +中的错误

c++ auto c++11

12
推荐指数
2
解决办法
8743
查看次数

标签 统计

auto ×1

c++ ×1

c++11 ×1