[C++/SDL2] Inheritance

Hi guys

After taking a break for several weeks I have to hurry and hand in my work in a few days ^^.

So if you could answer this one rather quickly I’d be thankful  Now let’s see… I’m trying to implement the enemy named goombas (from supermario) which is a derived class from SDLGameObject. I’m getting the following error:
C:\ C++ & SDL2\Super Mario Time Trip\Goombas.cpp|5|undefined reference to `vtable for CGoombas'|

It’s a little confusing since I’m using the exact same method as in the Player-class. I’m not getting an error there. I know there’ve been some other question just like this but I wouldn’t post here if I’d understood them…

Here’s some actual code: (I’ve cut out the in my eyes unnecessary parts)

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
#ifndef _SDLGAMEOBJECT_HPP_
    #define _SDLGAMEOBJECT_HPP_

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
#include "Sprite.hpp"
#include "Map.hpp"

class CSDLGameObject
{
    public:
        CSDLGameObject() {m_PosX = 0;
                          m_PosY = 0;
                          m_Width = 0;
                          m_Height = 0;
                          m_VelX = 0;
                          m_VelY = 0;
                          m_Gravity = 8;
                          m_CurrentFrame = 0;
                          m_CurrentRow = 0;
                          m_MovingSpeed = 0;
                          m_JumpingHeight = 0;
                          m_bIsJumping = false;
                          m_bLeft = false;
                          m_bRight = false;
                          m_bDead = false; }
	
    private:
        //the variables and such, cut them out

};


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


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include "Timer.hpp"
#include "Player.hpp"
#include "SDLGameObject.hpp"
#include "Map.hpp"
#include "Tile.hpp"
#include "TTF.hpp"


class CGoombas : public CSDLGameObject
{
    public:
        CGoombas(); 
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Goombas.hpp"
#include "Camera.hpp"

CGoombas::CGoombas() : CSDLGameObject() //Here is the error
{
    m_bRight = false;
    m_bLeft = true;
    m_bIsFalling = true;
    m_State = "WALKING";

    m_PosX = 400;
    m_PosY = 300;
    m_Width = 32;
    m_Height = 32;

    m_VelX = 4;
    m_VelY = 35;

    m_CurrentFrame = 0;
    m_CurrentRow = 0;

    m_Lives = 1;
}

Last edited on
Not so relevant advice:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Goombas.hpp"
#include "Camera.hpp"

CGoombas::CGoombas() : CSDLGameObject() //Here is the error
{
    m_bRight = false;
    m_bLeft = true;
    m_bIsFalling = true;
    m_State = "WALKING";

    m_PosX = 400;
    m_PosY = 300;
    m_Width = 32;
    m_Height = 32;

    m_VelX = 4;
    m_VelY = 35;

    m_CurrentFrame = 0;
    m_CurrentRow = 0;

    m_Lives = 1;
}
Why is that state a string?

Here's a tip: Only store data as a string if it's text that's manipulated by the program. A state doesn't have to be a string. It should be an enumeration.

Actual solution:
Have you tried changing the variables in the base class from private to protected?
http://ideone.com/CxUTKZ
Last edited on
Make sure you have defined all virtual functions.
@Avilius:
Ill memorise that  The variables already where protected, I typed in the private myself because I couldn’t copy everything. Some dumb error of mine ;)

The change from a string to an enumeration (wtf why did I ever take a string haha ^^’) is scheduled as well. Your help is very appreciated!

@Peter:
Hm and where did I miss out on the definition? :s

Something similar is already on google, but I don’t see an obvious error.
Can you give us a minimal example that reproduces the issue? What's given here seems perfectly valid.
Alright I've fixed it. The error wasn't in the code i posted before at all. I've deleted a few arguments in a function of my goombas class. It's just funny that codeblocks was pointing me to the constructor and not the function itself...

I'm sorry guys...
Topic archived. No new replies allowed.