这个gcc是过于好,做了开发认为它会做的事情,或者是铿锵的东西过于挑剔。我缺少标准的一些微妙的规则,其中铛是在抱怨这个铿锵:错误:无效使用非静态数据成员
或者我应该使用的代码的第二位,它基本上是offsetof是如何工作的
[[email protected] ~]$ g++ -Wall -pedantic -ansi a.cc
[[email protected] ~]$ a.out
50
[[email protected] ~]$ cat a.cc
#include <iostream>
struct Foo
{
char name[50];
};
int main(int argc, char *argv[])
{
std::cout << sizeof(Foo::name) << std::endl;
return 0;
}
[[email protected] ~]$ clang++ a.cc
a.cc:10:29: error: invalid use of non-static data member 'name'
std::cout << sizeof(Foo::name) << std::endl;
~~~~~^~~~
1 error generated.
[[email protected] ~]$ g++ -Wall -pedantic -ansi b.cc
[[email protected] ~]$ a.out
50
[[email protected] ~]$ cat b.cc
#include <iostream>
struct Foo
{
char name[50];
};
int main(int argc, char *argv[])
{
std::cout << sizeof(static_cast<Foo*>(0)->name) << std::endl;
return 0;
}
[[email protected] ~]$ clang++ b.cc
[[email protected] ~]$ a.out
50
嗯,我发现添加-std = C++ 11停止它抱怨。所以现在我想知道哪个部分对于我用这个代码违反的C++ 98。海湾合作委员会在任一版本都可以,但这并不意味着我没有违反规则 – Adrian 2015-03-31 14:34:13
不要通过添加评论来扩展你的问题。要么回答你自己的问题,接受它问一个新的问题。或编辑您的问题,包括标题,并删除不必要的部分。 – usr1234567 2015-03-31 14:52:13