我在 IAR 中有以下类结构:
class A
{
public:
A(){}
virtual ~A() {};
virtual void load() {};
};
class C
{
public:
C()
{
//C does other stuff, not relevant
}
};
class D;
class B : public A
{
public:
B() : invert(false) {};
virtual ~B() {};
void load()
{
//Irrelevant stuff done here
}
private:
C member_c;
std::vector<D*> vector_of_d;
struct {
bool var_1:1;
bool var_2:1;
bool var_3:1;
bool var_4:1;
bool invert:1;
};
};
Run Code Online (Sandbox Code Playgroud)
我遇到了为初始化 B 而生成的程序集的错误,它似乎对 VTable 指针的位置与匿名结构位域的位置感到“困惑”。当它设置反转位为假时,它转到对象的第一个字(即 VTable 指针)并翻转地址中的一个位。当我稍后调用 …