hi, I implemented a template base class for observer pattern,
template<class T>
class ActionListener
{
public:
ActionListener(void);
virtual ~ActionListener(void);
void registerListener(T* listener);
void unregisterListener(T* listener);
template<typename Signal>
void emit(Signal signal);
templa...
How do I obtain a function pointer for a class member function, and later call that member function with a specific object? I’d like to write:
class Dog : Animal
{
Dog ();
void bark ();
}
…
Dog* pDog = new Dog ();
BarkFunction pBark = &Dog::bark;
(*pBark) (pDog);
…
Also, if possible, I’d like to invoke the constructor via a ...
I'm trying to write a mapping function that takes a function pointer, and passes it to another function, but gcc is yelling at me.
Here is an idea of what I'm trying to do.
void map(T thing, void apply(int a, int b, void *cl), void *cl);
void function(T thing, void apply(int a, int b, void *cl), void * cl)
{
for(int i = 0; i < 10;...
Reading a question in stackoverflow, I wondered whether it's possible to declare a function that takes a pointer to itself. I.e. to make such declaration of foo, for which the following would be correct:
foo(foo);
The simpliest idea is casting to another function pointer (can't cast to void*, since it may be smaller), so the function...
Hello.
I am trying to do a very simple command line library for interactive Java programs. You start the Java program and it prompts you for commands. The syntax is:
> action [object_1, [object_2, [... object_n] ... ]]
for example:
> addUser name "John Doe" age 42
Here action = "addUser", object_1 = "name", object_2 = "John Doe", ...
I have a following class hierarchy:
class Base{
....
virtual bool equal(Base *);
}
class Derived1: public Base{
....
virtual bool equal(Base *);
}
class Derived2: public Derived1{
}
class Derived3: public Derived1{
}
class Derived4: public Base{
}
How I should write Base::equal(Base *) function such that compares Derived4 and similar...
I cannot figure the syntax to declare a function pointer as a static member.
#include <iostream>
using namespace std;
class A
{
static void (*cb)(int a, char c);
};
void A::*cb = NULL;
int main()
{
}
g++ outputs the error "cannot declare pointer to `void' member". I assume I need to do something with parentheses but void A::(*...
I have some binary data which contains a bunch of functions and want to call one of it.
I know the signature of these functions along with the offset relative to the start of the file. Calling convention is the default one: __cdecl.
The file was already loaded into a memory page with executing permissions.
For example (A, B, C being som...
Hello,
I am currently implementing a timer/callback system using Don Clugston's fastdelegates. (see http://www.codeproject.com/KB/cpp/FastDelegate.aspx)
Here is the starting code:
struct TimerContext
{
};
void free_func( TimerContext* )
{
}
struct Foo
{
void member_func( TimerContext* )
{
}
};
Foo f;
MulticastDelegate< ...
I have always been a bit stumped when I read other peoples' code which had typedefs for pointers to functions with arguments. I recall that it took me a while to get around to such a definition while trying to understand a numerical algorithm written in C a while ago. So, could you share your tips and thoughts on how to write good typede...
I don't know how to accomplish this!
how to get the function pointer in va_list arguments?
thanks so much.
...
I'm using reflection to examine the following method declaration and am wondering if it is possible to determine that the method's sole parameter is a function pointer.
public ref class T
{
public:
void foo(Int32 (*)(String^, array<TimeSpan>^)) { }
};
When inspecting the ParameterInfo object for foo's parameter, it shows that the ...
Why does this code
int (*g)(int);
int (*h)(char);
h = g;
In C, give me such warning when compiling:
'warning: assignment from incompatible pointer type'
In C++, can't be able to compile.
...
I want to pass an array of arbitrary struct pointers and a comparison function to a generic sorting algorithm. Is this possible in C?
The goooeys of the structs would only be accessed within the comparison function, the sorting function would only need to call the comparison function and swap pointers, but I can't figure out how to decl...
Instead of declaring a function pointer typedef for a function, is it possible to get it from the function declaration?
Typically,
int foo(int x);
typedef int (*fooFunc)(int);
fooFunc aFunc;
What I want:
int foo(int x);
foo* aFunc;
I want to use it for dlsym:
foo* aFunc;
aFunc = dlsym(lib, "foo");
aFunc(x);
If I update foo and ...
This is an excerpt of some c++ code, that i'll have to explain in detail in some days:
std::vector<int> vct(8, 5);
std::generate(vct.begin(), vct.end(), &rand);
std::copy(vct.rbegin(), vct.rend(),
std::ostream_iterator<int>(std::cout, "\n"));
i think i understand everything about it, except that tiny mystical &rand. what exactly...
void (*func)(int(*[ ])());
...
Is something like this possible to do in Java?
for (Object o : objects) {
for (Function f : functions) {
f(o);
}
}
I'm only calling a handful of functions, but I need to compose them, like so:
for (Object o : objects) {
for (Function f : functions) {
for (Function g : functions) {
f(g(o));
}
}
}
And I'd li...
How can I do this? (The following code does NOT work, but I hope it explains the idea.)
class MyClass
{
....
private:
int ToBeCalled(int a, char* b);
typedef (MyClass::*FuncSig)(int a, char* b);
int Caller(FuncSig *func, char* some_string);
}
I want to call Caller in some way like:
Caller(ToBeCalled, "stuff"...
Hi guys,
Is there any method to calculate size of a function? I have a pointer to a function and I have to copy entire function using memcpy. I have to malloc some space and know 3rd parameter of memcpy - size. I know that sizeof(function) doesn't work. Do you have any suggestions?
...