GetMenu': overriding virtual function return type differs and is not covariant from '

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • garimellasrinivasu
    New Member
    • Mar 2008
    • 2

    #1

    GetMenu': overriding virtual function return type differs and is not covariant from '

    Hi All,

    i am using VS2008 and trying to port my previous application which is working fine in VS2003.
    I am facing the following problem in this version(VS2008) .. Please guide me how to solve this ..

    error C2555: 'CGTDMenuBar::G etMenu': overriding virtual function return type differs and is not covariant from 'CWnd::GetMenu'

    C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\i nclude\afxwin.h (2245) : see declaration of 'CWnd::GetMenu'


    Thanks in advance!!


    Thanks & Regards
    Garimella Srinivasu
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I don't believe VS2003 supported covariance. I think that started with VS2005.

    Covariance in C++ when it comes to overriding virtual functions means that the return type of the overriding function can be different from the overriden function provided that the return type of the overriding function is lower (down) in the hierarchy.

    For example:
    [code=cpp]
    class Shape
    {
    public:
    virtual Shape* Copy();
    };
    class Ellipse : public Shape
    {
    public:
    virtual Ellipse* Copy(); //OK. Ellipse covariant in Ellipse
    //becuse it is lower in the hierarchy

    };
    class Circle : public Ellipse
    {
    public:
    virtual Shape* Copy(); //ERROR. Shape not covariant in Circle
    //because it is higher in the hierarchy
    };
    [/code]
    You will have to check your MFC hierarchy to see what's going. Considering the age of MFC, I would not be surprised to find that it is incompatible with the ANS C++ standard. You may have to tweak the design.

    Comment

    Working...