Jump to content
  • Advertisement
Sign in to follow this  
aarbron

constructor problem

This topic is 3949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
You need to pass an argument to the State constructor. Ex:

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!