Jump to content
  • Advertisement
Sign in to follow this  
lodoss118

help void pointers?

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

Hi i have method in a wrapper i am using which is need to register the primitives of your game inorder to allowe switching from fullscreen to window and other things this is the method used DXURegisterGraphicsProcs(void(*loadPrimitives)(),void(*releasePrimitives)(),void(*renderPrimitives)()); Now what i done i split this into for processes Load Release Render void methods for each structure/class. In my Intro class I have Intro::Load etc all the primitives ready but if i load DXURegisterGraphicsProcs(Intro::Load, Intro::Release, Intro::Render); it gives me this error 1>.\FusionIntro.cpp(40) : error C3867: 'FusionIntro::Load': function call missing argument list; use '&FusionIntro::Load' to create a pointer to member 1>.\FusionIntro.cpp(40) : error C3867: 'FusionIntro::Release': function call missing argument list; use '&FusionIntro::Release' to create a pointer to member 1>.\FusionIntro.cpp(40) : error C3867: 'FusionIntro::Render': function call missing argument list; use '&FusionIntro::Render' to create a pointer to member even if i use DXURegisterGraphicsProcs(&Intro::Load, &Intro::Release, &Intro::Render); i get >.\FusionIntro.cpp(40) : error C2276: '&' : illegal operation on bound member function expression 1>.\FusionIntro.cpp(40) : error C2276: '&' : illegal operation on bound member function expression 1>.\FusionIntro.cpp(40) : error C2276: '&' : illegal operation on bound member function expression In my main i have these primitives as public then it works but if i have them in a class which i need then it don't work how can i get around this?

Share this post


Link to post
Share on other sites
Advertisement
void(*loadPrimitives)() is a function pointer. By the looks of it, FusionIntro::Load is a member function, which means that &FusionIntro::Load is a member function pointer and cannot be used as a function pointer.

You will need to provide non-member (or static) functions as pointers to DXURegisterGraphicsProcs, and have them forward their calls to the member functions themselves.

Share this post


Link to post
Share on other sites
Quote:
Original post by lodoss118
so basically i should make FusionIntro a static class?


Not necessarily. You could keep it a normal class, and just have a standalone function which forwards the calls to a global instance or a global container of instances.

Quote:
isn;t there any easy way around it or :(.


DXURegisterGraphicsProcs has a brain-dead API, from the looks of it, so you have no choice.

Share this post


Link to post
Share on other sites
i.e becasue the load primitives creates new objects and release primitive s deletes the objects, how would this work if it is static?

Share this post


Link to post
Share on other sites
and just have a standalone function which forwards the calls to a global instance or a global container of instances. ?

Hi can you give me a quick example of how to do this, sorry for being a noob :(?

[Edited by - lodoss118 on July 16, 2007 5:32:27 AM]

Share this post


Link to post
Share on other sites
And to clarify a bit further as to why you cannot pass, it is due to the fact of implicit this pointer that is compiler generated. There are plenty of sources regarding this in the web, so I don't go further with the issue. Here is a link explaining member functions with more detail.

However, using member function pointers as callbacks is possible, sort of, as pointed out by others already. See this Boost::Bind documentation. Also Michael D. Crawford has some useful information written here.

Share this post


Link to post
Share on other sites
Quote:
Original post by lodoss118
Hi can you give me a quick example of how to do this, sorry for being a noob :(?


class DXUForwarder
{
static std::vector<Targets*> targets;

static void Setup()
{
DXURegisterGraphicsProcs(Load,Release,Render);
}

static void Load()
{
struct {
void operator(Target* t)() const { t -> Load(); }
} functor;

std::for_each(targets.begin(), targets.end(), functor);
}

static void Release()
{
struct {
void operator(Target* t)() const { t -> Release(); }
} functor;

std::for_each(targets.begin(), targets.end(), functor);
}

static void Render()
{
struct {
void operator(Target* t)() const { t -> Render(); }
} functor;

std::for_each(targets.begin(), targets.end(), functor);
}
};


Share this post


Link to post
Share on other sites
Glad i came across this thread, it solved a kindof related problem i was having. good explanation ToohrVyk and Naurava.

Share this post


Link to post
Share on other sites
Hi i nearly got everything working apart from this annoying error ?

1>FusionRegisterPrimitives.obj : error LNK2001: unresolved external symbol "protected: static class std::vector<class GameState *,class std::allocator<class GameState *> > FusionRegisterPrimitives::m_Register" (?m_Register@FusionRegisterPrimitives@@1V?$vector@PAVGameState@@V?$allocator@PAVGameState@@@std@@@std@@A)
1>C:\Documents and Settings\AMIR HAFEEZ\Desktop\Programming\Engine - LATEST\Fusion\Release\Fusion.exe : fatal error LNK1120: 1 unresolved externals




///header///

#ifndef FUSIONREGISTERPRIMITIVES_H
#define FUSIONREGISTERPRIMITIVES_H

#include "Globals.h"

class GameState;

class FusionRegisterPrimitives
{
public:
static void AddState(GameState *const pState);

static void Setup();

static void LoadCache();
static void RenderCache();
static void ReleaseCache();

protected:
static vector<GameState *> m_Register;
};

#endif


///cpp///
#include "FusionRegisterPrimitives.h"
#include "GameState.h"

void FusionRegisterPrimitives::AddState(GameState *const pState)
{
m_Register.push_back(pState);
}

void FusionRegisterPrimitives::Setup()
{
DXURegisterGraphicsProcs(LoadCache, ReleaseCache, RenderCache);
}

void FusionRegisterPrimitives::LoadCache()
{
struct{
void operator ()(GameState *s) const {s->LoadCache();}
}functor;

for_each(m_Register.begin(), m_Register.end(), functor);
}

void FusionRegisterPrimitives::RenderCache()
{
struct{
void operator ()(GameState *s) const {s->RenderCache();}
}functor;

for_each(m_Register.begin(), m_Register.end(), functor);
}

void FusionRegisterPrimitives::ReleaseCache()
{
struct{
void operator ()(GameState *s) const {s->ReleaseCache();}
}functor;

for_each(m_Register.begin(), m_Register.end(), functor);
}


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!