473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2324

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++? To be more specific, this is what I have. ...
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, how do I make my user control call a...
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 Dispose-Method.... but when set a breakpoint in 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 until W2K3, I need to do it myself. I'm fairly...
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. Basically I've got a class gs_object than has got...
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 not evaluate to a function taking 1 argument.. ...
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 n, int (*fun)(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 function call. This is usually a result of calling...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.