472,353 Members | 1,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

how call a method through an function pointer?

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
1 2278

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Eltee | last post by:
Hi everybody, Is it possible to 1. call a function from a dll made with .NET (C#) 2. from a program written in plain (as in: not .NET) C or C++?...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example,...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work...
20
by: alexandre.braganti | last post by:
Hello, First sorry for my poor English, I am French ;-) I've got a comprehension problem of what happend in one of the project i'm working on. ...
8
by: nsharma78 | last post by:
Hi, I have a code as follows: class A { public: void print(){cout << "Magic" << endl;} };
20
by: Bruce. | last post by:
I am trying to call a member function through a pointer to it and can't get the syntax exactly right. This compiles with an error C2064, term does...
3
by: Pawel_Iks | last post by:
I have following class definition (A.h file): class A { public: int N; int count1(int n) {n++;} int count2(int n) {n+=5;} int otherFun(int...
1
by: noony | last post by:
Here is the error I get after calling a method (described below) : Run-Time Check Failure #0 - The value of ESP was not properly saved across a...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.