making a game loop

So im transferring from Java and now im making a simple game loop. I made an abstract class with virtual so I can reuse my game engine core class. My game engine is called Faust. Anyways, the faust class has a game timer that calls the overrideable update and render functions every 60 FPS. My game class that inherits from faust is not responding to Faust's render and update. How do I go about and fix this?

faust.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef FAUST_H
#define FAUST_H

#include "gameloop.h"

class Faust{
    private:
        void start();
        ...
        GameLoop loop;

    protected:
        void virtual update() const;
        void virtual render() const;
    public:
        Faust(int Fps);
        ~Faust( void );

};
#endif // FAUST_H_INCLUDED 


faust.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "faust.h" //include faust engine headers
#include "SDL.h"
#include "SDL_opengl.h"
#include <iostream>

Faust::Faust(int Fps){
    loop = GameLoop(Fps);
    init();
    start();
}

Faust::~Faust( void ){
    SDL_Quit();
}

using namespace std;

void Faust::start(){
    while(loop.isRunning()){
        ...
        update();  //RIGHT HERE. My game.cpp class is not responding to this.
        cout<<"tick";
        ...
        render(); //same here
        ...
        //stabilize fps
        SDL_Delay(loop.getSleep());
    }
}
...

void Faust::update() const{}

void Faust::render() const{}


game.h

1
2
3
4
5
6
7
8
9
10
11
12
#ifndef GAME_H
#define GAME_H
#include "faust.h"
class Game: public Faust{
    protected:
        void update() const;
        void render() const;
    public:
        Game( int Fps = 60 );
        ~Game( void );
};
#endif // GAME_H 


game.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include "game.h"
#include "faust.h"

using namespace std;

Game::Game(int Fps):Faust(Fps){
}

Game::~Game(void){
}

void Game::update() const{
    cout<<"ticked";
    //This function should respond from the superclass Faust. But I dont know how to.
}

void Game::render() const{
    //same here
}



Any help appreciated. In java it was alot easier since it was just "abstract" class modifier
You can make Faust an abstract class by making at least one of the virtual function pure virtual.

Your problem is that you call the virtual functions from the constructor. http://www.parashift.com/c%2B%2B-faq-lite/calling-virtuals-from-ctors.html
Topic archived. No new replies allowed.