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

how can I persist a pointer to virtual member function?

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Tom" <bl**@blah.com> wrote in message news:p9*******************@news02.bloor.is.net.cab le.rogers.com...
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])();
}
};

Jul 19 '05 #2

P: n/a

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"Tom" <bl**@blah.com> wrote in message news:p9*******************@news02.bloor.is.net.cab le.rogers.com...
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;
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])();
}
};

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.