Thread: Cannot declare inherited class of virtual Base

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Cannot declare inherited class of virtual Base

    Anybody see what is going wrong here? i am compiling using codeblocks, when i try to make the ResetState class inherit from the StateEngine class i get error

    "expected unqualified-id before "public"
    |
    ||=== Build finished: 1 errors, 0 warnings ===|

    other classes are working fine as inherited, and the project has been built ok,
    its only when i add the text to make resetstate inherit that the problem occurs
    i have cleaned and done rebuild also.

    i cant see what i am doing wrong,
    below is the base class, resetstate class and resetstate constructor

    Base Class in header Globals.h >

    Code:
    #ifndef GLOBALS_H_INCLUDED
    #define GLOBALS_H_INCLUDED
    
    #include <SDL/SDL_events.h>
    #include <SDL/SDL_image.h>
    
    extern SDL_Surface* screen;              
    extern SDL_Surface* temp;
    extern SDL_Event event;                  
    
    class StateEngine                               //Base class
    {
        public:
        virtual void HandleEvents() = 0;
        virtual void Do_Logic() = 0;
        virtual void Render() = 0;
        virtual ~StateEngine(){};
    };
    
    
    #endif // GLOBALS_H_INCLUDED
    ResetState Class in header reset.h >

    Code:
    #ifndef RESET_H_INCLUDED
    #define RESET_H_INCLUDED
    
    #include <SDL/SDL.h>
    #include <SDL/SDL_events.h>
    #include <SDL/SDL_image.h>
    #include "Constants.h"
    #include "Globals.h"
    
    class ResetState public : StateEngine
    {
        private:
    
        SDL_Surface* Resetsourcemsg; 
        SDL_Surface* Buttonsource;  
        SDL_Rect resetmsg;
        SDL_Rect resetclip;
        SDL_Rect optionbutton[2];
        SDL_Rect optionclip[2];
    
        int count;
        int anim_count;
        int testX, testY;
    
        public:
    
        void HandleEvents();
        void Do_Logic();
        void Render();
    
        ResetState();
        ~ResetState();
    
    };
    
    #endif // RESET_H_INCLUDED
    The Constructor for ResetState in source file of same name >

    Code:
    #include <SDL/SDL.h>
    #include <SDL/SDL_events.h>
    #include <SDL/SDL_image.h>
    #include "Utilities.h"
    #include "Constants.h"
    #include "Globals.h"
    #include "reset.h"
    
    ResetState::ResetState()
    {
        temp = NULL;                            //this is global
        Resetsourcemsg = NULL;
        Buttonsource = NULL;
    
        temp = SDL_LoadBMP("Gameinfo.bmp");
        Resetsourcemsg = SDL_DisplayFormat(temp);
        SDL_FreeSurface(temp);
    
        temp = SDL_LoadBMP("Buttonsheet.bmp");
        Buttonsource = SDL_DisplayFormat(temp);
        SDL_FreeSurface(temp);
    
        testX = 0, testY = 0;
        anim_count = 0;
    
        resetmsg.x = 330;            //the reset game yes/no? message box
        resetmsg.y = 580;
        resetmsg.w = 500;
        resetmsg.h = 100;
    
     //for the sake of brevity i have removed the rest of the constructor, it just 
     // initialises the remaining SDL_Rect objects as in above resetmsg.x = etc.
    
    }
    Last edited by rogster001; 12-17-2009 at 08:56 AM.

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    colon's on the wrong side of public.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    haha, god i love it ...thing is now that threw another error 'expected class name before '{' token, think that is something to do ith my includes though, i will have to check, cheers

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    12
    Your includes? Maybe try the:

    #include "SDL_events.h"

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Your includes? Maybe try the:

    #include "SDL_events.h"
    Yea ok, that was added unneeded, nevertheless the include problem was adding reset.h to the globals header, copy paste mania, but now anybody for a bit of >

    Undefined reference to vtable for ResetState
    ??
    I see this a a bit of an FAQ elswhere and am looking up any advice but any answers appreciated

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    well i think its because i have not yet compiled the files that would provide at least one implementation of the virtual functions, they are in the project so doing that now and sure will solve, guaranteed to fail after saying that of course.

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    done!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 06-18-2009, 04:58 AM
  2. Declaring instances of different implementations
    By dwks in forum C++ Programming
    Replies: 8
    Last Post: 07-16-2008, 11:43 AM
  3. Replies: 3
    Last Post: 10-27-2006, 12:33 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM