• Advertisement
Sign in to follow this  

HGE FrameFunc as member function

This topic is 3546 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

Problem I'm trying to put some HGE calls in a class, but the compiler doesn't like me for trying to pass a member function as the frame function. Code game.h
#ifndef GAME_H
#define GAME_H

#include <hge.h>

class Game
{
public:
	Game();

	bool Initialize();
	void Start();
	void Shutdown();
private:
	void DisplayError();
	bool FrameFunc();
	bool LoadResources();

	HGE* hge;
};

#endif

game.cpp
#include "game.h"

Game::Game()
{
	hge = 0;
}

bool Game::Initialize()
{
	hge = hgeCreate( HGE_VERSION );

	hge->System_SetState( HGE_WINDOWED, true );
	hge->System_SetState( HGE_FRAMEFUNC, FrameFunc ); // <---
	hge->System_SetState( HGE_TITLE, "HGE Class Test" );
	hge->System_SetState( HGE_USESOUND, false );
	hge->System_SetState( HGE_HIDEMOUSE, false );

	if ( hge->System_Initiate() ) {
		if ( !LoadResources() ) DisplayError();
		return false;
	} else {
		DisplayError();
		return false;
	}
	
	return true;
}

void Game::Start() {
	hge->System_Start();
}

void Game::Shutdown()
{
	hge->System_Shutdown();
	hge->Release();
}

void Game::DisplayError() {
	MessageBox( NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR );
}

bool Game::FrameFunc()
{
	return false;
}

bool Game::LoadResources()
{
	return true;
}

main.cpp
#include "game.h"

int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	Game Pong;
	if ( Pong.Initialize() ) Pong.Start();
	Pong.Shutdown();

	return 0;
}

Error
Quote:
error C3867: 'Game::FrameFunc': function call missing argument list; use '&Game::FrameFunc' to create a pointer to member
Question Does anyone know how I could use my member function without making a lot of stuff static or having a global function with access to my class ( which I think would make my class globally accessible.. haven't put too much thought in that yet.. ) Please excuse any weird English and thank you in advance ^^.

Share this post


Link to post
Share on other sites
Advertisement
Take a look at the sticky FAQ topic in the HGE forums. There is an entry there that links to an explanation of how to handle this.

The short version is this: in order to use a member function for the frame and/or render functions, those functions must be declared static. Non-static member functions have no linkage and, therefore, no address.

Share this post


Link to post
Share on other sites
Thanks for your reply :D. I'd found those already but wondered if there was a way to do it without making it static and still have it as a member function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement