警告C4407可能导致什么问题? [英] What problems could warning C4407 cause?

查看:252
本文介绍了警告C4407可能导致什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过一些继承在某些MFC CWnd派生对象上使用纯虚拟接口收到了一些警告.我认为这是由于定义了消息映射需要实现的方法引起的.

I got some warnings by using pure virtual interfaces on some MFC CWnd derived objects through multiple inheritance. I believe it's caused by defining the methods which need to be implemented for the message map.

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

这听起来不只是警告,更像是可能导致堆损坏的事情.因此,还有另一种方法可以执行与下面类似的操作,而不会导致MFC动态向下转换宏比平时更加​​窒息吗?

That sounds like a bit more than a warning, more like something that might cause heap corruption. So is there another way to do something similar to below that won't cause the MFC dynamic downcast macros to choke anymore than usual?

class ISomeInterface
{
public:
     virtual LRESULT OnSomeRegisteredMessage(WPARAM wp, LPARAM lp) = 0;
};

class CSomeCoolWnd : public CWnd, public ISomeInterface
{
public:
     LRESULT OnSomeRegisteredMessage(WPARAM wp, LPARAM lp);
};

BEGIN_MESSAGE_MAP(CSomeCoolWnd , CWnd)
     ON_REGISTERED_MESSAGE(WM_USER_DEFINED, &CSomeCoolWnd::OnSomeRegisteredMessage)
END_MESSAGE_MAP()

我想出的唯一一件事就是从接口中注释掉消息处理程序,并留下注释告诉消费者他们应该实现它们.但是,最好通过编译器错误来强制执行此操作,而不是让它们使用接口并在运行时从丢失的内容中获得意外结果.

The only thing I've come up with is commenting out the message handlers from the interfaces and leaving comments telling the consumer that they should implement them. However it would be nice to enforce that through a compiler error rather than letting them use an interface and get unexpected results at runtime from things being missing.

推荐答案

可以在文章

An excellent description of the different representations of pointer-to-member values can be found at the article Member Function Pointers and the Fastest Possible C++ Delegates. Essentially, all the different inheritance types can require the use of different member function pointer representations. This is compiler-specific and the article talks about a number of different compilers (up to 2005 when the article was written).

很明显,对虚拟函数使用多重继承可能需要与简单的指针成员函数不同的表示形式. ON_REGISTERED_MESSAGE()中的某个地方可能有一个强制转换,在您发布的代码中看不到.

Evidently your use of multiple inheritance with virtual functions may require a different representation than a simple pointer-to-member function. There's probably a cast somewhere in ON_REGISTERED_MESSAGE() that isn't visible in the code you posted.

这篇关于警告C4407可能导致什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆