function-pointers

Python ctypes and function pointers

This is related to my other question, but I felt like I should ask it in a new question. Basically FLAC uses function pointers for callbacks, and to implement callbacks with ctypes, you use CFUNCTYPE to prototype them, and then you use the prototype() function to create them. The problem I have with this is that I figured that I would...

How come pointer to a function be called without dereferencing?

I have a weird typedef statement in a C++ program, generated by Py++. double radius(int); // function to be wrapped typedef double (*radius_function_type)(int); bp::def("radius", radius_function_type(&radius)); // bp::def is a function for wrapping What I figured out so far is that the above typedef statemnt is not of the type,...

mem_fun_ref trouble

I am having trouble figuring out mem_fun_ref. I have to admit, I usually use functors for this kind of thing, since they can be inlined for speed and profit. However, this code is not going to be a bottleneck and so I wanted to try this thing. Here is an example of what I want to do. I know there are other ways to do it. I don't want to...

how to assign a member function to an array and call it?

I'm currently doing it this way,but seems not the proper way: class Name { protected $jobs2do; public function __construct($string) { $this->jobs2do[] = $this->do; } public function do() { ... } } Because directly assign a function will cause warning,should do something like: function func() ...

Whats the difference between C# delegates, Dynamic Proxy, Closures and function pointers?

What are useful definitions for the common methods of passing a method or function as data, such as: Delegates Closures Function pointers Invocation by dynamic proxy and First class methods? ...

How to pass a function pointer that points to constructor?

I'm working on implementing a reflection mechanism in C++. All objects within my code are a subclass of Object(my own generic type) that contain a static member datum of type Class. class Class{ public: Class(const std::string &n, Object *(*c)()); protected: std::string name; // Name for subclass Object *(*create)(); // Po...

C++ function pointer (class member) to non-static member function

class Foo { public: Foo() { do_something = &Foo::func_x; } int (Foo::*do_something)(int); // function pointer to class member function void setFunc(bool e) { do_something = e ? &Foo::func_x : &Foo::func_y; } private: int func_x(int m) { return m *= 5; } int func_y(int n) { return n *= 6; } }; int main() { Fo...

Can operators be used as functions? (C++)

This is similar to another question I've asked, but, I've created an expression class that works like so: expression<int, int> exp(10, 11, GreaterThan); //expression<typename T, typename U> exp(T val1, U val2, oper op); //where oper is a pointer to bool function(T, U) where GreaterThan is a previously defined function. And I am wonde...

Best strategy to call an arbitrary function without using JMP or LCALL

In embedded C is quite natural to have some fixed/generic algorithm but more than one possible implementation. This is due to several product presentations, sometimes options, other times its just part of product roadmap strategies, such as optional RAM, different IP-set MCU, uprated frequency, etc. In most of my projects I deal with th...

How to make a function return a pointer to a function? (C++)

I'm trying to make a function that takes a character, then returns a pointer to a function depending on what the character was. I just am not sure how to make a function return a pointer to a function. ...

Polymorphic member function pointer

Hello, I'm trying to write a callback event system in DirectX9. I'm attempting to use method function pointers to trigger events to mouseclicks; but I'm having some problems. My game uses a gamestate manager to manage the rendering. All of my gamestates are derived from a base class AbstractGameState. I have a sprite object with this ...

How to take a pointer to a template function specialized on a string?

I was trying use a set of filter functions to run the appropriate routine, based on a string input. I tried to create matcher functions for common cases using templates, but I get a "type not equal to type" error when I try to store a pointer to the specialized function (in a structure, in the real application) Distilled example from a...

Function Pointers in Java

This may be something common and trivial, but I seem to be having trouble finding a concrete answer. In C# there is a concept of delegates, which relates strongly to the idea of function pointers from C++. Is there a similar functionality in Java? Given that pointers are somewhat absent, what is the best way about this? And to be clear, ...

A function pointer that points to a function that takes an object of a template class with said function pointer as template argument. Possible?

x__x I want to do something like this: typedef long (* fp)(BaseWindow< fp > & wnd, HWND hwnd, long wparam, long lparam); But I get a compile error: error C2065: 'fp' : undeclared identifier Is it possible to implement this somehow? ...

How can I pass a function by reference for a report callback in C++/CLI?

I have some code which handles data files and reports an error when it runs into trouble, but I'm having trouble working out how to give my class a callback function. Here's a quick example of the sort of thing I'm trying to achieve: public delegate void Reporter( System::String^ stringToReport ); /// <summary> /// Simple file handler ...

Function pointers casting in C++

Hi all, I have a void pointer returned by dlsym(), I want to call the function pointed by the void pointer. So I do a type conversion by casting: void *gptr = dlsym(some symbol..) ; typedef void (*fptr)(); fptr my_fptr = static_cast<fptr>(gptr) ; I hav also tried reinterpret_cast but no luck, although the C cast operator seems to work...

How to Convert Address to Function Pointer to Call Method

Hi, I wanted to call Test1() Method Within WaitAndCallFunc() Function. Code: typedef void (*func)(); void StartTimer(void* pFuncAddr); void WaitAndCallFunc(void* pPtr); void WaitAndCallFunc(void* pPtr) { int i = 0; int nWaitTime = 3; while(1) { Sleep(1000); // I want pPtr to call Test1 Function; if(i =...

pointer to const vs usual pointer (for functions)

Is there any difference between pointer to const and usual pointer for functions? When it is suitable to use const qualifier for stand alone functions? I wrote short sample to illustrate my question: #include <iostream> using namespace std; int sum( int x, int y ) { return x + y; } typedef int sum_func( int, int ); int main() { c...

What is going on with 'function pointer' or 'reference to function' as argument to function in C++?

In Numerical Recipes they use something I've never seen done before, and couldn't easily find info on: void fun( std::vector<double> derivatives(const double, const std::vector<double> &) ) { ...; derivatives(...); ...; } Which I'm guessing is passing the function by reference (is this correct)? Why would this be favorable to using a ...

How can I use a function pointer instead of a switch statement?

How can I use a function pointer instead of a switch statement? ...