首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么C++11 'auto‘关键字对静态成员无效?

为什么C++11 'auto‘关键字对静态成员无效?
EN

Stack Overflow用户
提问于 2013-01-12 03:22:53
回答 1查看 10.7K关注 0票数 13
代码语言:javascript
复制
class Foo {
 public:
  static const char *constant_string;
};

auto Foo::constant_string = "foo";

int main(void) {
};

编译: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3如下:

代码语言:javascript
复制
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]

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

EN

回答 1

Stack Overflow用户

发布于 2015-07-31 22:52:08

Visual C++接受

代码语言:javascript
复制
decltype(Foo::constant_string) Foo::constant_string = "foo";
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14285198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档