473,396 Members | 1,812 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,396 software developers and data experts.

how can I persist a pointer to virtual member function?

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
2 1902

"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

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

Similar topics

5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
4
by: DaKoadMunky | last post by:
I was recently looking at some assembly code generated by my compiler. When examining the assembly code associated with constructors I noticed that the dynamic-dispatch mechanism was enabled...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
1
by: none | last post by:
Hi, I have a base class with a pointer-to-member function variable. Then I have a derived class that needs to use that variable to call a member function (with the same arguments and return value...
6
by: Adrian | last post by:
Example A fails to compile with exampleA.cpp: In member function 'void A::a() const': exampleA:10: error: no matching function for call to 'A::b(const std::string&) const' exampleA:17: note:...
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
3
by: Dmitry | last post by:
Hi all, Consider the following code: class A { public: A() {} void DoMethod() { (this->*m_pMethod)(); } protected: virtual void MethodA() { ... }
7
by: ghulands | last post by:
I am having trouble implementing some function pointer stuff in c++ An object can register itself for many events void addEventListener(CFObject *target, CFEventHandler callback, uint8_t...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.