By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

how call a method through an function pointer?

P: n/a
i try to "publish" some of my very stupid methods (i need this for an interpreter)

function_one
procedure_one

here is the code

---------
class core
{
public:
int result;
int parameter[2];

typedef void(core::*call)();
typedef struct method_t
{
bool function; // additional information
call method; // the call
};

method_t methods[2];

core()
{
methods[0].function = true;
methods[0].method = function_one;

methods[1].function = false;
methods[1].method = procedure_one;
}

// callable methods
void function_one(){ result = parameter[0] + parameter[1]; }
void procedure_one(){ parameter[0] = 10; }
};

void main()
{
core c;

// why can't i call the method...
//c.methods[0].method();
// can't compile this - error
// error C2064: term does not evaluate to a function taking 0 arguments

// ...should be the same as
c.function_one();
}
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

dennis luehring wrote:
---------
class core
{
public:
int result;
int parameter[2];

typedef void(core::*call)();
typedef struct method_t
{
bool function; // additional information
call method; // the call
};

method_t methods[2];

core()
{
methods[0].function = true;
methods[0].method = function_one;

methods[1].function = false;
methods[1].method = procedure_one;
}

// callable methods
void function_one(){ result = parameter[0] + parameter[1]; }
void procedure_one(){ parameter[0] = 10; }
};

void main()
{
core c;

// why can't i call the method...
//c.methods[0].method();
// can't compile this - error
// error C2064: term does not evaluate to a function taking 0 arguments
// ...should be the same as
c.function_one();
}


Pointers to member functions are in the FAQ, but I can't help but think
that there must be a better way... Maybe polymorphism? What are you
trying to achieve?

http://www.parashift.com/c++-faq-lit...o-members.html

-Jason

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.