Skip to main content
gamedev.net
🔒 Locked

calling member function pointers from within the class

Started by drekkar 1 reply 700+ views
Original Post
drekkar
drekkar
Okay well first i'll state a simple situation thats quite simliar (yet far less complicated) to mine
class MyClass
{
public:
 MyClass();
 ~MyClass();
 void process();
 typedef void (MyClass::*funcPtr)();
 funcPtr sortedFunctions[256];
private:
 void randomFunctions();
 // ... many MANY functions like the avoid, all void no params
};

MyClass::MyClass(){
  funcPtr[0] = &MyClass::randomFunctions();
}

// Now below is where the problem arises... I cant seem to call 
// the function without an instance of the class 
// (therefore i cant call it from within the class as I want to)

void MyClass:rocess(){
  // ...
  sortedFunctions[0]();
}
  
so is there a way to make it so I can call sortedFunctions from within the class without an instance of the class? I thought making the functions static would work, but nothing I tried worked [edited by - drekkar on March 7, 2004 11:48:44 PM]
SiCrane
SiCrane
If I understand your question correctly, you might want to try:

void MyClass::Process(){
(this->*(sortedFunctions[0]))();
}
drekkar
drekkar
man it was so frustrating... thanks for the very fast reply!
it works! it wooooorks!!! ^.^

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.