Fernando A. Gómez F.
2009-03-02 07:35:02 UTC
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.
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
Fernando Gómez
www.fermasmas.com