Reputation: 134
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
Upvotes: 4
Views: 1616
Reputation: 656
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.
Upvotes: 0
Reputation: 531
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.
Upvotes: 7
Reputation: 1754
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.
Upvotes: 2
Reputation: 36092
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?
Upvotes: 1