为什么C11’auto’关键字对静态成员有效?
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像这样: 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中的错误 解决方法
这是不允许的语言:
很难证明是负面的,但在标准中根本没有明确的规定允许汽车在你的情况下. 但是,同样的规则意味着以下内容是有效的: struct Foo { static constexpr auto constant_string = "foo"; }; int main() {} (注意,Foo :: constant_string的类型是char const * const,而不是char const [3]; this is an effect of using (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |