這個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