开发平台(Platform): (Ex: Win10, Linux, ...)
Linux
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
GCC
问题(Question):
最近刚好看到侯捷的书,书中有个范例蛮特别的就去用GCC试试看
发现编译会错误
书上说class就算没变成object直取data member会是offset
可是我却得到编译错误
请问GCC不能这样取得offset嘛??
谢谢
错误结果(Wrong Output):
.cpp: In function ‘int main()’:
1.cpp:13:31: error: invalid use of non-static data member ‘TEST::a’
printf("addr = %p\n",&(TEST::a));
^
1.cpp:9:7: note: declared here
int a;
程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档)
include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
class TEST{
public:
int a;
};
int main() {
printf("addr = %p\n",&(TEST::a));
}