Sign in to follow this  
Arjan B

HGE FrameFunc as member function

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
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

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