having issue with Abstract class usage

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • having issue with Abstract class usage

      I used IScreenElement interface from the GameCode download and I am getting
      a strange error that I am trying to instantiate an abstract class (error C2259:
      'IScreenElement' : cannot instantiate abstract class). I made a list which I
      want to use to iterate through for drawing to the screen and I am currently
      stuck. The following is a partial class I wrote that inherits from
      IScreenElement.

      <code>
      #include "UIControl.h"
      #include "../interfaces.h"

      class Button : public UIControl , public IScreenElement
      {
      public:
      Button();
      ~Button();

      // IScreenElement Implementation
      HRESULT VOnRestore();
      HRESULT VOnRender(); // double fTime, float fElapsedTime
      void VOnUpdate(int deltaMilliseconds);
      int VGetZOrder();
      void VSetZOrder(int const zOrder);
      bool VIsVisible();
      void VSetVisible(bool visible);
      bool const operator <(IScreenElement const &other) { return VGetZOrder() <
      other.VGetZOrder(); }
      static void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, UIControl*
      pControl, void *pUserContext );
      LRESULT CALLBACK VOnMsgProc( AppMsg msg );
      // End of IScreenElement Implementation

      // UIControl Implementation
      bool OnRender(void);
      void OnMouseDown(int i_Button, int X, int Y); // what does i_Button mean in
      this context
      void OnMouseMove(int X, int Y);
      void OnMouseUp(int i_Button, int X, int Y); // what does i_Button mean in this
      context
      void OnSetFocus();
      void OnLostFocus();
      void OnKeyDown(WPARAM Key, LPARAM Extended);
      void OnKeyUp(WPARAM Key, LPARAM Extended);
      void OnSysKey(WPARAM Key, LPARAM Extended);
      // end of Control Implementation

      protected:
      ControlRect* m_Billboard;
      D3DXVECTOR3 position[4];
      D3DXVECTOR3 m_TopLeft;
      D3DXVECTOR3 m_TopRight;
      D3DXVECTOR3 m_BottomLeft;
      D3DXVECTOR3 m_BottomRight;
      </code>

      The compiler is telling me that HRESULT IScreenElement::VOnRestore(void)' : is
      abstract however I have created this method in the Button class (HRESULT
      VOnRestore();). I am not sure why this error is showing up when I clearly
      implemented all the virtual functions in my subclass.
    • Did you actually implement it, or did you just declare the function prototype in the header of the derived class? It needs to have a function body. Also, you might want to try and copy & paste the function prototype from the base to the derived class. Sometimes you can accidentally misspell something. If that doesn't work, sometimes yelling obscenities at your compiler will help. ;)

      -Rez