Trouble Calling Base Constructor

Started by
3 comments, last by Acticore 13 years, 2 months ago
I'm trying to build a class called MainGame that inherits from the class Game. Everything was coming along great until I needed to feed MainGame's constructor input into Game's constructor. Here's the code for the derived class MainGame:



#include <string>
#include "Game.h"

class MainGame : public Game
{
public:
MainGame(HWND *hwnd) : Game::Game(hwnd) {};

void Initialize();
void Update();
void Render();

void SetCaption(std::string newCaption) { Game::SetCaption(newCaption); };
};



This is the code for the class it derives from:


#include <windows.h>
#include <string>

class Game
{
public:
Game(HWND *hwnd);
Game();
~Game();

void Initialize();
void Update();
void Render();

void SetCaption(std::string newCaption);

private:
HWND *hwnd;
TCHAR szCaption[256];
};



The error I'm getting points to the this line of code in MainGame:

MainGame(HWND *hwnd) : Game::Game(hwnd) {};

and it looks like this:


error C2039: '{ctor}' : is not a member of 'Game'

What's going on, and what should I do to fix it? Thanks for any help you can give me. : )
Advertisement
I just realized I didn't include windows.h at the top of MainGame.h, but that doesn't change anything anyways. It's not complaining about HWND being undefined, and even with it included nothing changes.
Try
MainGame(HWND *hwnd) : Game(hwnd) {};
[color="#1C2837"][color="#660066"][color="#1C2837"][color="#660066"]MainGame[color="#666600"]([color="#000000"]HWND [color="#666600"]*[color="#000000"]hwnd[color="#666600"]) [color="#666600"]: [color="#660066"]Game[color="#666600"]::[color="#660066"]Game[color="#666600"]([color="#000000"]hwnd[color="#666600"]) [color="#666600"]{};
[color="#1C2837"]
[color="#1C2837"][color="#666600"]can just be
[color="#1C2837"]
[color="#1C2837"][color="#666600"][color="#1C2837"][color="#660066"]MainGame[color="#666600"]([color="#000000"]HWND [color="#666600"]*[color="#000000"]hwnd[color="#666600"]) [color="#666600"]: [color="#660066"]Game[color="#666600"]([color="#000000"]hwnd[color="#666600"]) [color="#666600"]{};
[color="#1C2837"][color="#666600"][color="#1C2837"]
[color="#666600"]
Thanks guys, I don't know why I didn't catch that. I had the call to the Game constructor inside another function originally and didn't get rid of the scope resolution operator when I moved it.

This topic is closed to new replies.

Advertisement