代码之家  ›  专栏  ›  技术社区  ›  Dr Deo

重载函数成员C++存在的问题

  •  1
  • Dr Deo  · 技术社区  · 15 年前

    我已经宣布一个班为

    class DCFrameListener : public FrameListener, public OIS::MouseListener, public OIS::KeyListener  
    {
        bool keyPressed(const OIS::KeyEvent & kEvt);
        bool keyReleased(const OIS::KeyEvent &kEvt);
    
    //*******some code missing************************   
    };
    

    但是如果我试着这样定义成员

    bool DCFrameListener::keyPressed(const OIS::KeyEvent kEvt)
    {
        return true;
    }
    

    编译器拒绝出现此错误

    error C2511: 'bool DCFrameListener::keyPressed(const OIS::KeyEvent)' : overloaded member function not found in 'DCFrameListener'  
    see declaration of 'DCFrameListener'
    

    为什么会这样,但我宣布 按键(const ois::keyEvent) 在我的函数声明中。

    任何帮助都将不胜感激。谢谢

    1 回复  |  直到 15 年前
        1
  •  12
  •   GManNickG    15 年前

    声明中的一个引用:

    bool keyPressed(const OIS::KeyEvent & kEvt);
                                        ^!
    bool DCFrameListener::keyPressed(const OIS::KeyEvent kEvt)
                                                        ^?