调用某些 MFC 默认构造函数时发生访问冲突

发布于 2024-11-26 13:59:19 字数 843 浏览 0 评论 0原文

由于昨天未能清楚地表达问题,我试图再次提出这个问题。基本上,我在下面代码的注释中描述了一个访问冲突错误...知道为什么吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漆黑的白昼 2024-12-03 13:59:19
  • 正确检查调用堆栈。
  • 确保对象分配正确,尝试在堆栈上分配它(而不仅仅是通过快捷方式)。
  • 检查其他类没有#pragma打包冲突。
  • 尝试从类 C 中删除一些数据成员。
  • Check the call stack properly.
  • Ensure object is allocated properly, try allocating it on stack (and not just by shortcut).
  • Check the other classes do not have #pragma packing conflicts.
  • Try removing some data-members from class C.
披肩女神 2024-12-03 13:59:19

我找到了解决我的问题的方法。问题的原因是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文