Sign in to follow this  
aarbron

constructor problem

Recommended Posts

I get the error " 'State' : no appropriate default constructor available " I'm trying to pass a function pointer in the constructor, is my syntax wrong ?
//==== state.h

class State
	{
	protected:
	void (*changeCallback)(State*);//owner's 'changestate' func
	public:
		State(void (*x)(State*)):changeCallback(x){};
		virtual ~State(){};
		virtual int Logic()=0;
		virtual void Render()=0;
	};

//==== State_GameMenu.h
#pragma once
#include "state.h"
#include "renderer.h"

class State_GameMenu : public State
	{
	public:
		State_GameMenu(void (*)(State*));
		~State_GameMenu(void);
		virtual int Logic();
		virtual void Render();
	};

//==== State_GameMenu.cpp
#include "State_GameMenu.h"

State_GameMenu::State_GameMenu(void (*cb)(State*))
	{
//error points here
	}

State_GameMenu::~State_GameMenu(void)
	{
	}
//etc.

Share this post


Link to post
Share on other sites
Unless you specify otherwise, the constructor of a derived class will call the default constructor of the base class. Since you haven't defined one, you get an error. If you want it to call a parameterized constructor instead, do this:


State_GameMenu::State_GameMenu(void (*cb)(State*)) : State (cb)


Also if you're going to be using callbacks, I recommend considering boost::function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this