how can I persist a pointer to virtual member function?

T

Tom

I have some virtual member functions like this:

struct IBlah {
virtual void f1() = 0;
virtual void f2() = 0;
}

I want to get a run-time identifier for one of these functions that I can persist (or send to a different process). I guess this is like what RPC does, in that it passes an ID of an interface function to a different process.

I think I remember that pointers to virtual member functions are actually just the offsets from the vtable. If so, then perhaps I could use those values?

Thanks,
Tom.
 
R

Ron Natalie

Tom said:
struct IBlah {
virtual void f1() = 0;
virtual void f2() = 0;
}

I want to get a run-time identifier for one of these functions that I can persist

A pointer to member can be used within the same program.
As far as something that persists or is handled outside of the same
program, you'll have to roll you're own.

struct IBlay {
static map<std::string, (void::*)()> func_map;

virtual void f1() = 0;
virtual void f2() = 0;

void InitializeMap() {
func_map["f1"] = &IBlay::f1;
func_map["f2"] = &IBlay::f2;
}

void InvokeNamedFunction(string name) {
(this->*func_map[name])();
}
};
 
C

Conrad Weyns

Ron Natalie said:
can persist

A pointer to member can be used within the same program.
As far as something that persists or is handled outside of the same
program, you'll have to roll you're own.

struct IBlay {
static map<std::string, (void::*)()> func_map;

static std::map<std::string, void (IBlay::*)() > func_map;

Cheers,
Conrad Weyns
virtual void f1() = 0;
virtual void f2() = 0;

void InitializeMap() {
func_map["f1"] = &IBlay::f1;
func_map["f2"] = &IBlay::f2;
}

void InvokeNamedFunction(string name) {
(this->*func_map[name])();
}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top