调用某些MFC默认构造函数时发生访问冲突
Access violation when calling some MFC default constructors
由于昨天没有说清楚,我想再问一遍这个问题。基本上,我有一个访问冲突错误描述在下面的代码注释中…知道为什么吗?
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;
}
- 正确检查调用栈
- 确保对象被正确分配,尝试在堆栈上分配(而不仅仅是通过快捷方式)。
- 检查其他类是否有
#pragma
包装冲突 尝试从
C
类中删除一些数据成员。我已经找到解决问题的方法了。问题的原因是类A被构建为具有与类B和c不同的结构对齐方式的dll。
相关文章:
- 使用 CTRP 时,是否访问访问父构造函数 UB 中的子属性?
- 访问在构造函数期间创建的值 - C++
- 我应该使用<Object> shared_ptr myObject = (shared_ptr) <Object>new Object() 来访问私有构造函数吗?
- 使用C 中的共享_ptr从公共静态成员函数访问私有构造函数
- 调用基构造函数时遇到问题 - 获取读取访问冲突
- 如何访问类构造函数中创建的对象
- 创建一个 const unique_ptr然后尝试从它 std::move 会给出与您尝试访问复制构造函数相同的错误
- 通过友元类访问私有构造函数
- 外部必须有权访问类构造函数
- 导致访问冲突的 fstream 构造函数
- 如何在单独的类中访问私有构造函数
- C++ 从数组访问重载构造函数
- 复制构造函数之后的flann::Index的析构函数产生访问冲突
- 将BSTR字符串传递给_BSTR_t或CComBSTR构造函数时发生访问冲突
- 声明和访问在构造函数c++中启动的2D-vector
- 访问模板构造函数和函数,包括静态和非静态
- 调用某些MFC默认构造函数时发生访问冲突
- 访问私有构造函数 C++
- 我的类(指向另一个类的指针容器)似乎无法访问公共构造函数
- c++基类中不可访问的构造函数