Discussion:
Message map and virtual inheritance causes C4407 warning
(too old to reply)
Fernando A. Gómez F.
2009-03-02 07:35:02 UTC
Permalink
Hello all. I have the following code:

class IMessageProvider;

class IMessageProcessor {
public:
virtual void UpdateMessages(IMessageProvider* pProvider) = 0;
};

class CCatalogDocument :
public CDocument, public virtual IMessageProcessor
{
DECLARE_MESSAGE_MAP();

public:
virtual void UpdateMessages(IMessageProvider* pProvider);
...
protected:
void OnCommandSave();
};

BEGIN_MESSAGE_MAP(CCatalogDocument, CDocument)
ON_COMMAND(ID_CATALOG_SAVE, OnCommandSave) // C4407
...
END_MESSAGE_MAP()

When I compile this code, I get the C4407 warning:
Cast between different pointer to member representations, compiler may
generate incorrect code.

The MSDN documentation says that:
C4407 can be generated because of compiler conformance work that was
done in Visual C++ 2005; pointer-to-members now require qualified name
and &. [...] C4407 can occur if you cast between a multiple inheritance
pointer-to-member to a single inheritance pointer-to-member. Sometimes
this can work, but sometimes it can’t because the single inheritance
pointer-to-member representation doesn’t hold sufficient information.
[...] You can also try rearranging your base classes; the compiler is
detecting a loss of information in the conversion because a base class
is at a non-zero offset from the derived.

So my only chance, as I understand it, is not to inherit virtually from
IMessageProcessor (when I remove the "virtual", the warning is gone).
However, I'd like to keep it virtual, since CCatalogDocument-derived
classes can inherit from IMessageProcessor-derived interfaces.

So I was wondering whether I can safely ignore this warning or not. Any
help or comments regarding this issue will be really appreciated.

Thanks in advance.
--
Fernando Gómez
www.fermasmas.com
d***@gmail.com
2015-09-07 01:17:18 UTC
Permalink
Hi all,
Now i'm try to convert from VS6.0 to VS2012 and met this warning a lot for multiple virtual inheritance.
I don't want to ignore the warning (such as /vmg or /vmb or #param disable...), so i try to search all the suggestion on google, but didn't find any good solution for this case.
Did anyone fix perfectly for this warning? Could you mind share with me your solution?

Thanks in advance.

Dustin Le

Continue reading on narkive:
Loading...