相关疑难解决方法(0)

使用"auto"的声明是否匹配使用具体类型说明符的extern声明?

考虑以下程序:

extern int x;
auto x = 42;
int main() { }
Run Code Online (Sandbox Code Playgroud)

Clang 3.5接受它(现场演示),GCC 4.9和VS2013不接受(前者的现场演示).谁是对的,C++标准中指定的正确行为在哪里?

c++ extern language-lawyer auto

56
推荐指数
1
解决办法
1816
查看次数

为什么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
查看次数

11
推荐指数
2
解决办法
305
查看次数