I created a base class which has data members and all the functions, except the constructor, are virtual.I want to derive new classes from it, but I get an error when compiling.
The header for the base class :
#ifndef GAMEAPP_H
#define GAMEAPP_H
#define nmax 128
#include<SDL/SDL.h>
#include<fstream.h>
class CGameApp
{
public:
SDL_Surface *backgv[nmax];
SDL_Surface *btnv[nmax];
char backgloc[nmax][100];
char btnloc[nmax][100];
ifstream backgf, btnf;
int backgn,btnn,currentbackg;
CGameApp(){};
virtual ~CGameApp(){};
virtual void modify();
virtual void initialize();
virtual void show();
virtual void free();
};
#endif
The header for the derived class:
#ifndef MAINMENU_H
#define MAINMENU_H
#include "CGameApp.h"
class CMainMenu : public CGameApp
{
public:
CMainMenu(char *backgfile, char *btnfile)
{backgf.open(backgfile);btnf.open(btnfile);}
CMainMenu(){}
~CMainMenu(){backgf.close();btnf.close();}
void initialize();
void modify();
void execute();
void free();
void show();
};
#endif
Definitions for the derived class:
#include "CMainMenu.h"
void CMainMenu :: initialize()
{
int i;
backgf>>backgn;
for(i=1;i<=backgn;i++)
backgf>>backgloc;
btnf>>btnn;
for(i=1;i<=btnn;i++)
btnf>>btnloc;
}
void CMainMenu :: modify()
{
if(currentbackg<backgn)
++currentbackg;
else
currentbackg = 1;
}
void CMainMenu :: free()
{
}
void CMainMenu :: execute()
{
}
void CMainMenu :: show()
{
}
And the main :
#include "CMainMenu.h"
int main(int argc,char *argv[])
{
CMainMenu obj1;
//ofstream g("test.out");
return 0;
}
The error is at the last line of the main source .The linker gives this .
E:/Programs/ProiecteSDL/BasicGameTemplate/main.cpp:8: undefined reference to `vtable for CGameApp'
obj\Debug\main.o(.text$_ZN8CGameAppD2Ev+0x3a):E:/Programs/ProiecteSDL/BasicGameTemplate/main.cpp:8: undefined reference to `vtable for CGameApp'
What am I doing wrong ?