All Questions

Tagged with
Filter by
Sorted by
Tagged with
129 votes
8 answers
185k views

How can I define a class member as a pointer to another member function?

I'd like to set up a function pointer as a member of a class that is a pointer to another function in the same class. The reasons why I'm doing this are complicated. In this example, I would like the ...
Mike's user avatar
  • 59.1k
26 votes
4 answers
9k views

Dynamic method dispatching in C

I know it sounds silly and I know that C is not an Object Oriented Language. But is there any way that dynamic method dispatching can be achieved in C? I thought about function pointers but don't get ...
Dineshkumar's user avatar
  • 4,165
12 votes
6 answers
2k views

C++ function pointers and classes

Say I have: void Render(void(*Call)()) { D3dDevice->BeginScene(); Call(); D3dDevice->EndScene(); D3dDevice->Present(0,0,0,0); } This is fine as long as the function I want ...
Fire Lancer's user avatar
  • 29.4k
4 votes
5 answers
1k views

How can I pass a module's function as a reference to another module in Perl?

How can I pass a reference to a module's function as parameter in a function call of another module? I tried the following (simple example): This is the module that has a function (process_staff) that ...
Cratylus's user avatar
  • 53.1k
4 votes
2 answers
2k views

Covariance and contravariance in C++ function pointer?

Consider this class Base { }; class Derived : public Base { }; Base *f1(Derived *) { return {}; } Derived *f2(Derived *) { return {}; } // covariant Base *f3(Base *) { return {}; } // ...
vbstb's user avatar
  • 1,271
3 votes
6 answers
157 views

Does functional pointers not support instance types in C++

I am trying to understand how to use functional pointers to map the method from instances in C++ like delegates in C#. class FunctionalPointers { public: static int IncrementCounter ( int *a, ...
Karthik's user avatar
  • 187
3 votes
3 answers
262 views

Why the delegates or closures often referred as true "object-oriented function pointers"?

For example, considering the C# Unlike function pointers in C or C++, delegates are object-oriented, type-safe, and secure. source: http://msdn.microsoft.com/en-us/library/...
user827992's user avatar
  • 1,743
3 votes
3 answers
456 views

java : Function objects as strategies

I am reading Effective Java. In a section that talks about using function objects as strategies, the below paragraph is present. Because the strategy interface serves as a type for all of its ...
Vinoth Kumar C M's user avatar
3 votes
1 answer
846 views

Function Pointer as a Friend Function

I am using function pointers within a class to allow extendable functionality at runtime. I have typedef'd the function signature: typedef f32 generate_height(f32 x, f32 y); Now, within the class I ...
Louis Piper Carson's user avatar
2 votes
5 answers
872 views

Equivalent of C NULL function pointer in C++?

A common practice in C to implement "Object Oriented" is using an array of function pointers. This seems to be similar to the C++ vtable and in essence the C++ virtual functions mechanism is just ...
shoosh's user avatar
  • 77.1k
2 votes
2 answers
97 views

How to pass function pointer to member function c++?

So this is like my 2nd question regarding the topic but this time I want to know what if i pass a function which is of int type.Like here I want to store output of fun1 in variable "int my" in main ...
codie's user avatar
  • 33
2 votes
3 answers
2k views

C++ Override Pure Virtual Function with Function Pointer

If I have a pure virtual function can it be overriden with a function pointer? Scenario below (I'm aware that it's not 100% syntactically correct): #include<iostream> using namespace std; ...
Eliezer's user avatar
  • 7,219
2 votes
1 answer
135 views

Fortran: procedure pointer to method

I'm in the following situation: I have an object that must be initialized (without hurry) with some input parameter x. Then it has a method do_work that has to run (fast). Now, depending on x the ...
MaPo's user avatar
  • 633
2 votes
3 answers
829 views

Passing states of StateMachine as parameter to a function pointer C++ OOP

I'm fairly new to the concept of function pointer in C++, so I don't know how to write my question properly. Please bear with me. Basically, what I'm trying to do is to create a Button object whose ...
user2345939's user avatar
1 vote
3 answers
246 views

Is it possible to use a pointer to an uninstantiated object as a variable in C++?

I want an attribute in a C++ class be an uninstantiated class from a particular class heirachy. All members of this class heirachy would then implement the same method, meaning I could instantiate the ...
CiaranWelsh's user avatar
  • 7,094
1 vote
1 answer
333 views

Fortran Functions with a pointer result in a normal assignment

After some discussion on the question found here Correct execution of Final routine in Fortran I thought it will be useful to know when a function with a pointer result is appropriate to use with a ...
ATK's user avatar
  • 1,306
1 vote
1 answer
717 views

Passing a function pointer to a member function in C++.Getting error

Hi it is my first experience with passing function pointer in C++. So here is my code:- #include <iostream> using namespace std; // Two simple functions class student { public: void fun1() { ...
codie's user avatar
  • 33
1 vote
2 answers
4k views

Calling member function of one class from another

I have this problem with a big piece of code which have some event handling objects. In an event handling class I am trying to call a function of another class through pointer but it is having same ...
QT-ITK-VTK-Help's user avatar
1 vote
1 answer
1k views

C++ passing dynamic method pointer as a method argument of different class

I'm making an allegro game in which button class should be independent so I'm putting function pointer inside of button object for OnClick event. Progressing through the project I've been putting ...
thormond's user avatar
1 vote
1 answer
164 views

Can we turn such structure into typed class/function?

So in structure like struct RenderCastedDataFunctor { simpleRendererGraphElement* obj_; RenderCastedDataFunctor(simpleRendererGraphElement* obj) : obj_(obj) { } void operator()(...
Rella's user avatar
  • 65.1k
1 vote
1 answer
196 views

one class should invoke method of another class using a function pointer

I have consult (disclaimer): Class member function pointer Calling C++ class methods via a function pointer C++: Function pointer to another class function To illustrate my problem I will use this ...
user avatar
1 vote
1 answer
389 views

Accessing a member function from another class without prior knowledge of the specific member function

I want to create a class that will access the member functions of a family of classes. Going into more detail, I have class ControlChaos which is declared like this: #define CALL_MEMBER_FN(object, ...
Joey Dumont's user avatar
0 votes
2 answers
92 views

pointer to member function in C++

I have problem in this line std::cout << &X::a << std::endl; this line print 1 supposed to printed address of &X::a this my code #include <iostream> #include <string>...
Hassan Lakhal's user avatar
0 votes
3 answers
119 views

Does "this" also adapt to function pointers?

Java has a construct that allows a method to call itself via a "this()" reference. The name of this convention escapes me at the moment. EDIT: Known as Constructor Delegation as pointed out below. ...
Daniel Park's user avatar
  • 3,903
0 votes
2 answers
179 views

Clean method to call interface functions with a vector of objects

I have a vector of tasks implementing the same interface. I have a state machine object that can have multiple tasks, and I have a whole bunch of events. If a particular event is called, I would ...
pyInTheSky's user avatar
  • 1,459
0 votes
1 answer
80 views

Scope Error for a member function of a class

#include <iostream> using namespace std; class Model { private: double a, b; double (*fPtr)(double); public: //Constructor Model(double lowerLimit, double upperLimit, double (*...
ask1504's user avatar
  • 27
0 votes
1 answer
476 views

Context independent C++ TCP Server Class

I'm coding a TCP Server class based on the I/O multiplexing (select) way. The basic idea is explained in this chunk of code: GenericApp.cpp TServer *server = new Tserver(/*parameters*/); server->...
fitzbutz's user avatar
  • 956
0 votes
2 answers
139 views

Passing a function as a parameter to a method in C++

I want to make a method for a (mathematical) matrix class to process objects with the function given in parameter, but I'm stuck with function pointers! My code: #include <iostream> class ...
Balázs Kóti's user avatar
0 votes
1 answer
364 views

Getting class' method address

I'm asking you to help me understand this concept. Maybe I don't understand something, I don't know.. So I have this sample code: #include <iostream> class X{ int a; public: ...
todovvox's user avatar
  • 170
0 votes
1 answer
287 views

Execute arbitrary function pointer

Im interested in creating arrays of functions which don't take arguments and don't return anything. Is there a way to create a generic function pointer and execute it? Example: ptr ptrArray[1]; ...
FourierFlux's user avatar
0 votes
1 answer
60 views

Member template function pointers errors

I am using a pointer to a template member function as follows in my "Array" class : //Sorts elements according to the value of sortFn (ascending) template<typename T> template<...
Yosry's user avatar
  • 147
0 votes
1 answer
140 views

How to set the argument of a function pointer of type its parent structure

I try to define function pointers as the members of the structure which can access and modify other parameters of the structure (like functions of a class in OOP). For this, I have a structure with ...
Behy's user avatar
  • 483
0 votes
1 answer
45 views

initialize and apply structure-parameters using function pointers as structure members

In the following code: #include <stdio.h> #include <stdlib.h> typedef struct{ int a; int b; int (*func1)(); int (*func2)(); }STR_X2; void init(STR_X2 self , int _a , int ...
Behy's user avatar
  • 483
0 votes
1 answer
660 views

C++: OpenMP: Copying function pointers for multithreading

I have a parallelized fitting program (parallelized with OpenMP) that takes the function that it has to fit using function pointers. I've been facing problems, and eventually I found out that I pass ...
The Quantum Physicist's user avatar
0 votes
0 answers
44 views

How to reduce amount of memory taken by function pointers in structs? [duplicate]

I'm trying to implement some kind of OOP in C. I have a struct Foo that has a funcion pointer to some function: struct Foo { void (*func)(); }; The problem here is that every instance of this ...
Sun of A beach's user avatar
0 votes
1 answer
46 views

Using a function pointer array to call a method of a class

I would like to write a program in C++ which contains an array of function pointers. Here is the code: #include <iostream> using namespace std; class MyClass { int a, b; public: ...
Samuil Iliev's user avatar
0 votes
0 answers
745 views

C++: cannot convert A::lambda() to B::*function pointer in assignment

I have a OneWireDriver class: class OneWireDriver; typedef void (OneWireDriver::*StateHandler)(void); class OneWireDriver{ Timer *timer; //a pointer to a Timer object working for this ...
Slighten's user avatar
0 votes
1 answer
295 views

Function pointers implication to Object-oriented programming

In his talk "The Future of Programming", Robert Martin mentions the motives for structured, functional and object-oriented paradigms: Structured programming: don't use unrestrained goto; Functional ...
ebu_sho's user avatar
  • 394
0 votes
1 answer
43 views

Add functions from a child class into list of functions pointers in abstract parent class

I have an abstract class that has a list of function pointers, and I want to insert into that list pointers to functions in a subclass. I have the following code: class Parent { public: ...
swooders's user avatar
  • 151
0 votes
2 answers
462 views

cannot convert 'int (B::*)(std::string)' to 'int (*)(std::string) ' in assignment pt2function=&B::generate_callback;

I am new to c++, .I am trying to create a pgm that contains 2 classes ,out of which one class has a member function that would generate a callback function in another class though a function pointer, ...
TheNVP's user avatar
  • 5
0 votes
2 answers
77 views

php pass function reference to another function to be executed on return

in this example; if i call wash_hands then it will first execute $this->eat() then $this->log(). but what i really want is that $this->log to be executed first then $this->eat() function ...
Zalaboza's user avatar
  • 8,919
-1 votes
1 answer
121 views

Set pointer in class

i'm new to c++, and i start a project with SFML. I need a class that can handle sprite, so i do: #pragma once #include <SFML/Graphics.hpp> #include <iostream> class Particle { private: ...
Flitzcore's user avatar
  • 166
-1 votes
2 answers
144 views

PHP, How can I sum-up the numeric values after calling a function from within a class?

The program deals 5 cards to each player displaying images of the cards along with the cards number value, after user selects number of players. Everything works as described above, but I don't know ...
BeetleThug's user avatar
-2 votes
3 answers
126 views

call function from static pointer to another class inside a class

I have problems understanding the below code. I searched using Google but I could not find an answer. class B { //constructor etc //...some stuff virtual myinit(); virtual doStuff(); }...
afro_samuray's user avatar