Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


void* problem

This topic is 5617 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 am implementing a TaskManager, what i want is that any class that want to define a task will simply send a structure to the TaskManager. this structure will hold information about the task (name, expiration time etc) plus a pointer to the method of the class in question. I know that i can''t have a general method pointer to any method of any class, i have to specify the class, so i was thinking about using a void* pointer. But it did''n work, Is it possible to do such manipulation? or i have to absolutely cast the pointer before calling the method? here''s what my code look like: the structure: struct sTask { int nID; int nType; bstring szName; bstring szOwner; void* pMth; }; the setting of the task informations: // i must do that so it can compile void (CStarGate::*pmth)(void); pmth =&CStarGate::taskBlink; sTask task; task.nID = CGlobalInfo::Instance()->getUniqueID(); task.nType= TASK_MONO_CYCLE; task.pMth = &pmth; task.szName="taskBlink"; task.szOwner="CStarGate"; this->vTask.push_back(task); //this vector is later read by the task manager then in my TaskManager i try to call the method, i try many way but none work. It''s the first time I am dealing with void* pointer and i can''t find descent documentation, do you have any link or idea about this problem? thanks

Share this post

Link to post
Share on other sites
i hope i understood that correctly. anyway, here i go:

you could define a common interface (or in this case, a base class)for every class which wants to implement a task function, like this:

class TaskBase

//task manager calls this when it''s time for it.

//just change ''params'' to any type you need..

virtual void OnTask ( void* params ) = 0;

sTask TaskInfo; //your struct


you can derive any class you want from this class. then, in the TaskManager you keep a list of pointers to all objects, and it walks through the list and calls the OnTask() method.

this would be more elegant because of the unified interface instead of arbitrary function names etc. of all the different classes.

is that what you want?

Share this post

Link to post
Share on other sites
yea well that was my first implementation, but maybe a class will want to define more then one task, so that''s why it would be nice to have the pointer thing.

Share this post

Link to post
Share on other sites
what you want is



void *

two very different things, value pointers and function pointers

EDIT: two not too :-/

[edited by - null_vector on June 2, 2003 1:02:57 PM]

Share this post

Link to post
Share on other sites

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