有人可以向我解释为什么该offsetof
函数在 std::vectors 上不起作用,如下所示:
#include <windows.h>
#include <iostream>
#include <vector>
using namespace std;
struct FooStruct {
double x;
double y[10];
std::vector<double> z;
};
int main() {
cout << offsetof(FooStruct, x) << endl;
cout << offsetof(FooStruct, y[2]) << endl;
cout << offsetof(FooStruct, z[2]) << endl;
system("Pause");
}
调用offsetof(FooStruct, z[2])
会产生以下编译错误:
cannot apply 'offsetof' when 'operator[]' is overloaded