Inheritance : What am I doing wrong?

Hi, I expected this to work but it does not, can anyone explain?

1
2
3
4
5
6
class Event{

   public:
   void HandleEvent(SDL_Event& Event); //Defined in Event.cpp (omitted)

};


1
2
3
4
5
class Game : public Event{

//Definition of rest of the class (omitted)

};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "Game.h"
#include "SDL.h"
#include "Event.h"

int main(int argc, char* argv[])
{
  Game* game = Game::GetInstance(); //(This is a singleton)

  //some intermediate code here (where Event is defined)

        game->HandleEvent(&Event);

  //blah blah blah


error: no matching function for call to `Game::HandleEvent(SDL_Event*)'
note: candidates are: void Event::HandleEvent(SDL_Event&)

I am confused a) why can't it find HandleEvent? I thought this was the entire idea of inheritance!
b) Why does it think I have sent a pointer when I have sent a reference?

Thank you to anyone who can explain! :D
You *are* sending a pointer. Putting the & in front of a variable gives you the address (making it a pointer). If you want a reference, just pass the variable normally and it will be converted to a reference automatically.
Thanks firedraco! Such a "duh" moment for me!
Topic archived. No new replies allowed.