member-function-pointers

Pointer to a class member

I am using Boost Spirit parser, and as the parser is parsing, semantic actions are reflected to an instance of the class ParserActions. Here is the code for the parser (the relevant part) struct urdf_grammar : public grammar<urdf_grammar> { template <typename ScannerT> struct definition { definition(urdf_grammar const& se...

What type can hold member-function-pointers of difference classes in C++?

Hi all, I need an array to hold member-function-pointers of different classes. How can I define the array? The code should look like this : arr[0] = &CMyClass::FuncX; arr[1] = &CYourClass::FuncY; arr[2] = &CHerClass::FuncZ; I tried void*, but it doesn't work. Thanks. Best regards, Zach@Shine ...

Question about member function pointers in a heirarchy

I'm using a library that defines an interface: template<class desttype> void connect(desttype* pclass, void (desttype::*pmemfun)()); and I have a small heirarchy class base { void foo(); }; class derived: public base { ... }; In a member function of derived, I want to call connect(this, &derived::foo); but it seems that &der...

Function pointers to member functions

There are several duplicates of this but nobody explains why I can use a member variable to store the pointer (in FOO) but when I try it with a local variable (in the commented portion of BAR), it's illegal. Could anybody explain this? #include <iostream> using namespace std; class FOO { public: int (FOO::*fptr)(int a, int b); int ad...

Member Function Pointer not quite right

I have a SpecialisedRedBlackTree class that is templated. My Month class is not. In my Month class I have a private member which is an instance of SpecialisedRedBlackTree: SpecialisedRedBlackTree<Day> m_windSpeedTree; As you can see it will take the Day class/object (please correct me on any terms I get wrong). In my Month class, I...

c++ generic pointer to (member?) function

I can't seem to declare a generic pointer to function. Having these 2 functions to be called: void myfunc1(std::string str) { std::cout << str << std::endl; } struct X { void f(std::string str){ std::cout<< str << std::endl;} }; and these two function callers: typedef void (*userhandler_t) (std::string); struct example {...

handling pointer to member functions within hierachy in C++

Hi, I'm trying to code the following situation: I have a base class providing a framework for handling events. I'm trying to use an array of pointer-to-member-functions for that. It goes as following: class EH { // EventHandler virtual void something(); // just to make sure we get RTTI public: typedef void (EH::*func_t)(); protect...

Is a pointer to a virtual member function valid in the constructor of the base class?

My question is not about calling a virtual member function from a base class constructor, but whether the pointer to a virtual member function is valid in the base class constructor. Given the following class A { void (A::*m_pMember)(); public: A() : m_pMember(&A::vmember) { } virtual void vmember() { ...

C++: pointer-to-member-func, template & inheritance mixup

I am trying to create a generic "callback" object that will hold arbitrary data and invoke member functions of related classes. Due to internal policy, I cannot use Boost. The callback object looks like this: template<typename Object, typename Data> class Callback { public: typedef void (Object::*PHandler)(Callback*); Callback(Obj...

Call a member function with bare function pointer

What's the best way to call a member function if you have an object and a bare function pointer pointing to the member? Essentially I want to call the function pointer with thiscall calling convention. Background: I'm looking up symbols in a shared library dynamically, obtaining a factory function pointer and a pointer to a certain memb...

How do you pass a function of a class as a parameter to another function of the same class

i basically want to use a dif function to extract a different element of a class (ac). the code is similar to this: .h: class MyClass { public: double f1(AnotherClass &); void MyClass::f0(AnotherClass & ac, double(MyClass::*f1)(AnotherClass &)); }; .cc: double MyClass::f1(AnotherClass & ac) { return ac.value; } void M...

Object-Oriented Callbacks for C++?

Hi! Is there some library that allows me to easily and conveniently create Object-Oriented callbacks in c++? the language Eiffel for example has the concept of "agents" which more or less work like this: class Foo{ public: Bar* bar; Foo(){ bar = new Bar(); bar->publisher.extend(agent say(?,"Hi from Foo!", ?));...

MSVS2010 linker error sadness - not entirely sure what is wrong

I am using a library of code from a tutorial for providing functionality for passing function points of non-static member functions to a function that expects a static function pointer, probably helps to know what I am suing, so here is the link http://www.codeproject.com/KB/cpp/thunk32.aspx This code uses the Boost library, which I have...

What is the practical use of pointers to member functions?

I've read through this article, and what I take from it is that when you want to call a pointer to a member function, you need an instance (either a pointer to one or a stack-reference) and call it so: (instance.*mem_func_ptr)(..) or (instance->*mem_func_ptr)(..) My question is based on this: since you have the instance, why not call ...

Member-function pointers and phantom classes

I've been messing about with member-function pointers in relation to a previous question. In the code below I call methods on a class (B) that change a variable (count) in it, but I never make an instance of this class. Why does this work? #include <iostream> #include <string> #include <map> class A; typedef int (A::*MEMFUNC)(int, int)...

Use C structs only and stay OOPy?

Say you have: struct c_struct { int value; /* other stuff */ void (* dump)(); }; and you'd like to, at some point: c_struct_obj->dump(); I assume there's no way you could instantiate a c_struct object such that its particular "dump" function knows its particular "value" the way C++ methods know member variables (via the im...

Member function pointer

If the following from the C++ FAQ Lite is true: "a function name decays to a pointer to the function" (as an array name decays to a pointer to its first element); why do we have to include the ampersand? typedef int (Fred::*FredMemFn)(char x, float y); FredMemFn p = &Fred::f; And not just: typedef int (Fred::*FredMemFn)(char x, flo...

Problem with pointer to a member function

In code below (please see comment): #include "stdafx.h" #include <iostream> using std::cout; struct Base { void fnc() { cout << "Base::fnc()"; } }; struct Impl { void* data_; Impl(void (Base::*fp)()) { fp();//HERE I'M INVOKING IT - I'M DOING SOMETHING WRONG! } }; int _tmain(int argc, _TCHAR* argv[]) { return 0; } ...

error C2064: term does not evaluate to a function taking 0 arguments

In some code I'm writing, I have the following line, which gives me error C2064: rs_opCodes[cur_block](); rs_opCodes is defined as such: typedef void (rsInterpreter::*rs_opCode)(); rs_opCode rs_opCodes[NUM_OPCODES]; Does anyone know why I'm recieved error C2064? ...