调用某些 MFC 默认构造函数时发生访问冲突
由于昨天未能清楚地表达问题,我试图再次提出这个问题。基本上,我在下面代码的注释中描述了一个访问冲突错误...知道为什么吗?
Class A
{
private:
BOOL a;
BOOL b;
int i;
public:
A() {a = FALSE; b = FALSE; i = 0;}
....
}
Class B : public A
{
public:
B() {} // empty constructor
....
}
Class C
{
public:
C() {} // <-- when the constructor is calling the CButton and CCombobox
// default constructor for the member "cb" and "button", it overrides
// the address space of some of the variables defined in class A
// (e.g. a, and b would be changed to some garbage)
// Basically, any variable defined below 'y' will have similar
// problems, though not exactly the same variables from 'y' will
// be changed..
private:
int x;
B y;
CCombobox cb;
CButton button;
}
I am attempting to ask this question again due to my failure to state the question clearly yesterday. Basically, I have an access violation error described in the comment in the code below... any idea why?
Class A
{
private:
BOOL a;
BOOL b;
int i;
public:
A() {a = FALSE; b = FALSE; i = 0;}
....
}
Class B : public A
{
public:
B() {} // empty constructor
....
}
Class C
{
public:
C() {} // <-- when the constructor is calling the CButton and CCombobox
// default constructor for the member "cb" and "button", it overrides
// the address space of some of the variables defined in class A
// (e.g. a, and b would be changed to some garbage)
// Basically, any variable defined below 'y' will have similar
// problems, though not exactly the same variables from 'y' will
// be changed..
private:
int x;
B y;
CCombobox cb;
CButton button;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
#pragma
打包冲突。C
中删除一些数据成员。#pragma
packing conflicts.C
.我找到了解决我的问题的方法。问题的原因是 A 类构建到一个 dll 中,其结构对齐方式与 B 类和 C 类不同。
I've found the solution to my problem. The cause of the problem is that Class A is built to a dll with a different struct alignment than class B and C.