[Dev-C++] Problems with function pointers inside a class
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <cg...@wo...> - 2002-12-27 11:20:58
|
Hi:
I am trying to use the title of the message.
I declare:
class{
...
typedef void (classname::*funny)(void**); //I tried either void
(classname::*function[19])(void**);
funny *function; OR funny function[19];
};
Then
class::class(){
function = new funny[19];
function[0] = &class::function1_name;
:
function[18] = &class::function19_name;
}
Then inside another function:
int cuantos = rand() % 19;
(this->*function[cuantos])(NULL);
^-- Or &void_pointer_*, or
void_pointer_**, or (void**)int_pointer_**, set to NULL or not
initialized or initialized.
I read this is the correct way for doing this, and
(this->*function[cuantos]) is the only syntax the compiler accepts.
When it's time to use the function it crashes.
Right now all the functions are:
void class::functionx(void** tas){
cout << "functionx" << endl;
}
What I see in my code is done as "Thinking in C++" says it must be done.
|