17
votes
3answers
480 views

Non-pointer typedef of member functions not allowed?

After getting an answer to this question I discovered there are two valid ways to typedef a function pointer. typedef void (Function) (); typedef void (*PFunction) (); void foo () {} Function * p = ...
8
votes
3answers
1k views

Table of function pointers within a class C++

I'm trying to make a table of function pointers within a class. I haven't been able to find any examples of this online, most involve using member function pointers outside of their class. for ...
8
votes
4answers
336 views

Why the size of a pointer to a function is different from the size of a pointer to a member function?

Isn't a pointer just an address? Or I'm missing something? I tested with several types of pointers: pointers to any variables is the same (8B on my platform) pointers to functions are the same ...
7
votes
5answers
1k views

How to define a general member function pointer

I have created a Timer class that must call a callback method when the timer has expired. Currently I have it working with normal function pointers (they are declared as void (*)(void), when the ...
6
votes
4answers
7k views

Passing member function pointer to member object in c++

I have a problem with using a pointer to function in C++. Here is my example: #include <iostream> using namespace std; class bar { public: void (*funcP)(); }; class foo { public: bar ...
6
votes
2answers
889 views

C++: Using function pointers with member functions

I'm trying to pass a function to another function as a parameter, and they both happen to be member functions of the same class. I'm getting a weird error and I can't figure out what the problem is. ...
5
votes
2answers
212 views

Pointers to members representations

I'm trying to make some callbacks from member functions and everything was ok until I tried to use a template class derived from 2 classes as callback object when I got the following error: error ...
5
votes
3answers
581 views

Function pointers to member functions in C++

I need to call a method that expects a function pointer, but what I really want to pass to it is a functor. Here's an example of what I'm trying to do: #include <iostream> #include ...
4
votes
4answers
291 views

To pass a pointer to a member function

I have an class with instance functions (or methods?). From within an instance, I try to pass pointers to those functions to a library. The library expects static functions. When I pass my pointers ...
4
votes
3answers
2k views

C++ Pointer to virtual function

If you have a struct like this one struct A { void func(); }; and a reference like this one A& a; you can get a pointer to its func method like this: someMethod(&A::func); Now ...
4
votes
4answers
953 views

c++ store a pointer to a member function of unknown class

I want to store a pointer to an object and a pointer to it's method of known signature. If I know the class then this pointer have type: int (MyClass::*pt2Member)(float, char, char) But how can i ...
4
votes
1answer
115 views

Pointer to function member and non-member

Abstract I have a class that stores a optimization problem and runs a solver on that problem. If the solver fails I want to consider a sub-problem and solve using the same solver (and class). ...
3
votes
4answers
654 views

Start a thread using a method pointer

I'm trying to develop a thread abstraction (POSIX thread and thread from the Windows API), and I would very much like it to be able to start them with a method pointer, and not a function pointer. ...
3
votes
3answers
1k views

Cast member function for create_pthread() call

I want to stop the warning server.cpp:823: warning: converting from 'void* (ClientHandler::)()' to 'void ()(void)' in the call: pthread_create(th, NULL, (void* (*)(void*)) ...
3
votes
2answers
242 views

get function ptr to member function of instanced class?

class gfx { void resize(int x, int y); } gfx g; can i cast g.resize to a 'void (*)(int, int)' somehow?

1 2 3 4
15 30 50 per page