开发者

Static_cast compiler error in C++ sdi application

I have a small SDI application to which I am trying to add tracking of menu usage, ie. how many times certain menu items are selected by the user.

Some menu items are handled by the View component (DemoView.cpp) and others by the main app (DemoApp.cpp). Since the tracking structure is defined in the main app, I believe that I have to notify the View's parent with a special message when a menu item (handled by the View) is selected.

If this is correct, my problem is that I cannot create the proper ON_MESSAGE command. It looks like this :

 ON_MESSAGE(WM_INCREASE_FREQ, &CDemoApp::OnIncreaseFreq)

where OnIncreaseFreq() is defined like 开发者_运维百科this :

LRESULT CDemoApp::OnIncreaseFreq(WPARAM, LPARAM)

However I get this error :

error C2440: 'static_cast' : cannot convert from 
'LRESULT (__thiscall CDemoApp::* )(WPARAM,LPARAM)' to 
'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

I would appreciate any help with this


According to the error, the callback function must be a member function of a class that derives from CWnd. Make CDemoApp derive from CWnd and your code should compile and work.


If you are sure about the conversion, you need to use another cast. It's called the dreaded reinterpret_cast<>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜