编译时错误 C4407

发布于 2024-08-19 07:08:45 字数 466 浏览 8 评论 0原文

我们的代码中有以下类结构。

Class A: public CDialog, public Base1, public Base2
{
};

在 A 类的实现中,我们有以下内容:

BEGIN_MESSAGE_MAP( A, CDialog )
    ON_WM_SIZE()
END_MESSAGE_MAP()

请注意 Base1 和 Base2 不是从 CDialog 或任何其他 MFC 类继承。

在 VC6 上编译成功。但在 VC9 上,我们得到以下错误代码:

错误 C4407:在指向成员表示的不同指针之间进行转换,编译器可能会生成不正确的代码

该错误代码指向ON_WM_SIZE的位置。

谁能告诉我一个解决方案。提前致谢。

游戏玩家

We have the following class structure in our code

Class A: public CDialog, public Base1, public Base2
{
};

In implementation of Class A we have the following:

BEGIN_MESSAGE_MAP( A, CDialog )
    ON_WM_SIZE()
END_MESSAGE_MAP()

Please note Base1 and Base2 doesn't inherit from CDialog or any other MFC classes.

On VC6 the compilation is successful. But on VC9 we get the following error code:

error C4407: cast between different pointer to member representations, compiler may generate incorrect code.

This error code is pointing to the location of ON_WM_SIZE.

Could anyone possibly tell me a solution. Thanks in advance.

Gamer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

本王不退位尔等都是臣 2024-08-26 07:08:46

我刚刚解决了这个问题的一个例子;通过网络搜索发现了这个问题。

就我而言,我还有一个对话框类继承自多个类:CDialog 和 ConfigurationTab,这是一个内部接口。
通过更改以下内容可以消除编译器警告:

class Foo : public ConfigurationTab, public CDialog

with:

class Foo : public CDialog, public ConfigurationTab

当有问题的对话框在分配给 DDX 变量时在 ON_BN_CLICKED 方法内崩溃时,我们发现了这种情况。当我们确定 DDX 变量已初始化时,该变量在该行神秘地未初始化。

I just solved an instance of this problem; found this question with a web search.

In my case I also had a dialog class inheriting from more than one class: CDialog and ConfigurationTab, which is an internal interface.
The compiler warning was silenced by changing:

class Foo : public ConfigurationTab, public CDialog

with:

class Foo : public CDialog, public ConfigurationTab

We discovered this situation when the offending dialog crashed inside a ON_BN_CLICKED method at an assignment to a DDX variable. The DDX variable was mysteriously uninitialized at that line, when we were sure it was initialized.

执手闯天涯 2024-08-26 07:08:46

我手边没有安装的 V9,但我可以看到在 VS6 和 VC8 之间,ON_WM_SIZE 定义已更改为语义上相同,但在它接受的内容上更加严格。 VC6 使用 C 强制转换,而 VC8 使用 C++ 强制转换,这会捕获更多问题。

我们需要查看您的 OnSize 方法类的实际声明,我认为才能确定这里出了什么问题。

I don't have an installed V9 handy, but i can see that between VS6 and VC8 the ON_WM_SIZE define has changed to be semantically the same but far more stringent in what it accepts. VC6 used C casts, where VC8 is using C++ casts which catch more problems.

We would need to see the actual declaration from your class of the OnSize method i think to be able to determine what is going wrong here.

不美如何 2024-08-26 07:08:46

只是猜测,自从我使用 MFC 以来已经有一段时间了,但看起来它对您的多重继承

BEGIN_MESSAGE_MAP( class, baseclass )

扩展为调用“类”中的方法感到困惑,因此由于 A 是多重继承的,因此不确定使用其中的哪一个,也许您在几个基类中有相同的方法?

Just guessing, been a while since I did MFC but it looks like it gets confused of your multiple inheritance

BEGIN_MESSAGE_MAP( class, baseclass )

expands to calling a method in 'class' so since A is multiple inherited its uncertain which of them to use, maybe you have the same method in several of the base classes?

还在原地等你 2024-08-26 07:08:46

就我而言,类 Base2 有虚拟方法。例如。

class Base2
{
 virtual void method(){};
}

时,会出现警告。

Class A: public CDialog, public Base1, public virtual Base2
{
};

当我使用定义类 A

如果我在这里删除 virtual 关键字。

Class A: public CDialog, public Base1, public Base2
{
};

然后警告就消失了。请注意,我没有删除 Base2 主体中的虚拟。就在 A 类定义中。

希望它可以帮助你。

in my case, the class Base2 has virtual method. eg.

class Base2
{
 virtual void method(){};
}

and the warning occurs when I use

Class A: public CDialog, public Base1, public virtual Base2
{
};

to define the class A.

If I remove the virtual keyword here.

Class A: public CDialog, public Base1, public Base2
{
};

then the warning disappeared. Please note I didn't remove virtual in the body of Base2. Just in class A definition.

Hope it can help you.

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