How to pass method of a class into another function in C++? - c++

Say I have a class and a function
class A
{
int a;
int b;
int mul()
{
return a+b;
}
};
...
void func(int af, int bf, int (*fc)())
{
...
}
In the main function, the function is supposed to use the methods of class A
int main
{
A as;
...
func(as.a, as.b, as.mul);
}
However, I can't do that, the compiler keeps telling me that I'm passing
(int&, int&, 'unresolved overloaded function type')
into a function of candidate
(int, int, void(*)()).
Why is that, and how to pass method of a class into another function?
Oh, I think I should make the problem a little bit clearer. func(...) is actually a function from an algorithm I'm working on. And class A is a model that will use the algorithm to do the simulation. So I don't think I'll specifically use the instance of A in function B, but only pass A's methods and components in and work with them.
Update: Some have mentioned using static methods in class A. However, this is still a partial solution. Using static method mul() will force me to claim a and b both to be static. And if I have to use multiple instances of A, with method a, b different in each instance in my main function, using static variables will simply fail.
So, are there other suggestions on how to fix this without using static variables/methods? I remember in script languages such as python, passing methods of whatever type is basically not an issue. Why can't I do a similar thing in C++? Or are there workarounds in C++ that can help me do this?

First of all, mul is a member function of A, so you can't invoke it as if it was a global function or a static member function: it needs an object on which the function is invoked:
A::mul(); // ERROR!
A a;
a.mul(); // OK
This said, you could change the definition of func to accept a pointer-to-member-function:
void func(int af, int bf, void (A::*fc)())
// ^^^^^^^^^^^^^^^
However, this change alone won't make you progress too much, because you're still not passing the concrete instance of A on which the member function should be invoked. In other words, this would be illegal:
fc(); // ERROR!
To over come this limitation, you could pass a reference or a pointer to an instance of A together to func, and call it as done below:
void func(A* pA, int af, int bf, void (A::*fc)())
{
...
(pA->*func)();
}
However, if func() has the object on which the member function should be invoked passed in as an argument, it is not clear what is the purpose of af and bf.
Possibly, if your mul() member function does not need to work on any concrete instance of A, and still you want to make it a member of A, you could declare it as static:
class A
{
int a;
int b;
static void mul();
// ^^^^^^
};
This would make your original call to func() compile. However, in this case it is not clear whether this would make sense, since the fact that mul() accept no arguments suggests that it is supposed to work on the a and b members of the object it is invoked on.

Is mul indended to be a non-static member, needing an object of type A to invoke it on? In that case, you'll need to pass a pointer-to-member:
void func(int af, int bf, void (A::*fc)())
{ // ^^^
A a = whatever();
(a.*fc)();
}
If it's intended to be called without an object, then it needs to be static.

What you want to do is to pass a member function pointer (A::mul) along with the instance (a) itself. That's not that easy without any additional code.
Member function pointers aren't tied to an instance (they only represent the function itself, not the instance on which to be called on). Their type is described together with the class name. The type of a member function pointer on A with the signature of your func will look like this:
void (A::*)() // The type only, anonymous
void (A::*fc)() // An actual function pointer with the name `fc`
To call such a function, you have to use the following syntax, in which, as you can see, the instance to call the function on, has to be involved:
(a->*fc)(); // If a is of type A*
(a.*fc)(); // If a is of type A or A&
To put things together, you have basically two options.
Also pass the instance (as a pointer, a reference, either const or modifiable) in addition to a member function pointer. Then, call the member function pointer on that instance.
You're function's signature and implementation will then look like this:
void func(int af, int bf, void (A::*fc)(), A *a) {
// When you want to call the function fc on a:
(a->*fc)();
}
To call func, use a code like this:
func(as.a, as.b, &A::mul, a);
Convert the member function pointer together with the instance to a functor which can be called as is. This can be best done with std::mem_fn together with std::bind1st.
You're function's signature and implementation will then look like this:
void func(int af, int bf, std::function<void()> fc) {
// When you want to call the function fc:
fc();
}
To call func, use a code like this:
func(as.a, as.b, std::bind1st(std::mem_fn(&A::mul), a));

If you really want to treat int (*fc)(int,int) (void return and empty parameter list given in another example) as a regular function pointer (I mean not function pointer to class member function), You can do the following to use the function of A and pass it into func. The point is to declare mul as static member function. I am assuming very simple operation like multiplication.
#include <iostream>
class A
{
public: //necessary otherwise not accessible in main
int a;
int b;
A(int p1, int p2):a(p1),b(p2){} //assume you need to somehow pass a,b into mul
static int mul(int p1, int p2) {return p1*p2;}; //mul should be static
};
void func(int af, int bf, int (*fc)(int,int))
//using void still work but you need to change declaration of mul in A
{
int res = fc(af,bf);
cout << res <<endl;
}
int main()
{
A as(2,4);
func(as.a, as.b, &A::mul); //call A::mul, use as regular function pointer, output 8
func(10,10, &A::mul); //will output 100
return 0;
}
This way you are using the static member function of A that can be pointed to by a regular function pointer. It has nothing to do as a and b inside the class anymore.

As leemes said, you can do this with std::function which is what I would recommend as well, but check out what your compiler has support for, and if so, you can use a single call to std::bind and have it work. Example below that works on Visual Studio 2012 (and should work on newer versions of GCC with the flag for C++11 enabled, and may or may not work on VS 2010)
void func(int af, int bf, std::function<void()> fc)
{
fc();
}
call with:
func(as.a, as.b, std::bind(&as::mul, &A));
The newer versions of std::bind do the std::mem_fcn part for you if it detects a member function. See the doc linked here:
std::function
std::bind

Related

C++ Functor as an argument of an external fortran function [duplicate]

I'm trying to use a C library in a C++ app and have found my self in the following situation (I know my C, but I'm fairly new to C++). On the C side I have a collection of functions that takes a function pointer as their argument. On the C++ side I have objects with a functor which has the same signature as the function pointer needed by the C function. Is there any way to use the C++ functor as a function pointer to pass to the C function?
You cannot directly pass a pointer to a C++ functor object as a function pointer to C code
(or even to C++ code).
Additionally, to portably pass a callback to C code it needs to be at least declared
as an extern "C" non-member function.
At least, because some APIs require specific function call conventions and thus
additional declaration modifiers.
In many environments C and C++ have the same calling conventions and differ only
in name mangling, so any global function or static member will work.
But you still need to wrap the call to operator() in a normal function.
If your functor has no state (it is an object just to satisfy some formal
requirements etc):
class MyFunctor {
// no state
public:
MyFunctor();
int operator()(SomeType &param) const;
}
you can write a normal extern "C" function which creates the functor and executes its
operator().
extern "C" int MyFunctorInC(SomeType *param)
{
static MyFunctor my_functor;
return my_functor(*param);
}
If your functor has state, eg:
class MyFunctor {
// Some fields here;
public:
MyFunctor(/* some parameters to set state */);
int operator()(SomeType &param) const;
// + some methods to retrieve result.
}
and the C callback function takes some kind of user state parameter (usually void *):
void MyAlgorithmInC(SomeType *arr,
int (*fun)(SomeType *, void *),
void *user_state);
you can write a normal extern "C" function which casts its state parameter to
your functor object:
extern "C" int MyFunctorInC(SomeType *param, void *user_state)
{
MyFunctor *my_functor = (MyFunctor *)user_state;
return (*my_functor)(*param);
}
and use it like this:
MyFunctor my_functor(/* setup parameters */);
MyAlgorithmInC(input_data, MyFunctorInC, &my_functor);
Otherwise the only normal way to do it
(normal as in "without generating machine code at runtime" etc.)
is to use some static (global) or thread local storage to pass the functor
to an extern "C" function.
This limits what you can do with your code and is ugly but will work.
I found this "gem" using google. Apparently possible but I sure wouldn't recommend it. Direct link to example source code.
No, of course. The signature of your C function take an argument as function.
void f(void (*func)())
{
func(); // Only void f1(), void F2(), ....
}
All tricks with functors are used by template functions:
template<class Func>
void f (Func func)
{
func(); // Any functor
}
A C callback function written in C++ must be declared as an extern "C" function - so using a functor directly is out. You'll need to write some sort of wrapper function to use as that callback and have that wrapper call the functor. Of course, the callback protocol will need to have some way of passing context to the function so it can get to the functor, or the task becomes quite tricky. Most callback schemes have a way to pass context, but I've worked with some brain-dead ones that don't.
See this answer for some more details (and look in the comments for anecdotal evidence that the callback must be extern "C" and not just a static member function):
C++ Using Class Method as a Function Pointer Type
I don't think you can: operator() in a function object is really a member function, and C doesn't know anything about those.
What you should be able to use are free C++ functions, or static functions of classes.
GCC allows you to convert member function pointers to plain function pointers (the first argument of the function called by the plain function pointer then is this).
Check out the respective link in the manual.
This requires the -Wno-pmf-conversions flag in order to silence the respective warning for the decidedly non-standard feature. Very convenient for interfacing C style libraries with C++ style programming. When the member function pointer is a constant, this does not even need to generate any code at all: the API would use that argument order anyway.
If you already have a functor, flattening the functor in that manner will likely mean flattening its operator(), giving you a function that has to be called with a functor class pointer itself as its first argument. Which does not necessarily help all that much but at least has C linkage.
But at least when you are not going through functors this is helpful and provides a no-nonsense C linkage replacement for std::mem_fn from <functional>.
It depends if this is a static or instance method, if it is static then you can pass through the function as className::functionName, if it is an instance method it is fair more complicated, because you obviously need to tie to a certain instance but can't do it in the same way as you would with delegates in C# etc.
The best way I've found of doing this is to create a holding class which is instantiated with the instance of the object as well as the function pointer, the holding class can then invoke the function directly.
I would say no, because a C++ functor has an overloaded operator () which is a member function, and would thus require a member function pointer. This is a totally different data type than a normal C function pointer, since it cannot be invoked without an instance of the class. You'd need to pass a normal function or a static member function to the C library. Since an overloaded () operator can't be static, you can't do it. You'd need to pass the C-library a normal, non-member function or static member function, from which you can then invoke the C++ functor.
Hm, maybe you could write a free template function that wraps around your function-objects. If they all have the same signature, this should work. Like this (not tested):
template<class T>
int function_wrapper(int a, int b) {
T function_object_instance;
return funcion_object_instance( a, b );
}
This would do for all function that take two ints and return an int.
Many C APIs that take function pointer callbacks have a void* parameter for user state. If you've got one of those, you're in luck - you can use an exterm C function that treats the user data as some sort of reference or key to lookup the functor, then execute it.
Otherwise, no.
With C++11, you can use std::bind to solve the problem
#include <stdio.h>
#include <functional>
class aClass
{
public:
int i = 5;
aClass(int i_) : i(i_) {}
void operator()(int a, int b) {
i = i + 1;
printf ("%d + %d = %d i = %d\n", a, b, a + b + i, i);
}
};
void test (int a, int b)
{
printf ("%d - %d = %d\n", a, b, a - b);
}
template <class op>
void function1 (op function)
{
function (1, 1);
}
int
main (int argc, const char *argv[])
{
aClass a(1);
// function1 (a); // this is the wrong way of using it
using namespace std::placeholders;
std::function<void(int,int)> callback;
callback = std::bind(&aClass::operator(), &a, _1, _2);
function1 (callback);
function1 (callback);
function1 (test);
function1 (test);
return 0;
}

C++ pointer to a function

In my code I would like to call different functions by the same name. So I used pointers, and I did work with static functions, now I would like to do the same with non-static functions and it doesn't work at all.
class Amrorder
: {
public:
....
void (*fkt)(real&, const real);
void fktAcPulse(real &rhoRef, const real y);
void fktAcPulseSol(real &rhoRef, const real y);
...
}
void Amrorder::initData(a)
{
...
switch(method){
case 2://
Amrorder::fkt=&Amrorder::fktAcPulse;
break;
case 222://
Amrorder::fkt=&Amrorder::fktAcPulse1d;
break;
}
...
for(int i=0; i<ng; ++i){
Amrorder::fkt(rhoRef, yRef);
...
}
...
}
The code is quiet big so I hope the part above is enough to understand what I want to do.
Thanks for your time!
It doesn't work because your fkt has type:
void (*)(real&, const real);
and you're trying to assign it to, e.g., &Amrorder::fktAcPulse, which has type:
void (Amrorder::*)(real&, const real);
Notice the difference. The latter is a pointer-to-member function, not just a pointer to function. These have different semantics. A pointer to function can just be called (e.g. fkt(a, b)), but a pointer to member function needs to be called on an object (e.g. (obj.*pm)(a, b)).
For simplicity, since you probably just want "something that I can call with a real& and a const real", you may want to consider the type-erased function object: std::function:
std::function<void(real&, const real)> fkt;
This can be initialized with any callable that matches the arguments, so you can assign it to a free function:
void foo(real&, const real) { ... }
fkt = foo;
A static member function:
struct S { static void bar(real&, const real) { ... } };
fkt = &S::bar;
Or a member function, as long as its bound:
fkt = std::bind(&Amrorder::fktAcPulse, this);
fkt = [this](real& a, const real b){ return this->fktAcPulse(a, b); };
The key is that you need an instance of Amrorder to call fktAcPulse, and using std::function lets you use either std::bind or a lambda to store that instance in with the functor itself.
The type of fkt declares a function pointer to a free-standing function or a static member function. But you want to assign a non-static member function pointer to it. So fkt needs to be of the type of a non-static member function pointer of class Amrorder. That type is spelled
void (Amrorder::*fkt)(real&, const real);
// ^^^^^^^^^^
When invoking a function pointer to a non-static member function, you need to specify on which object you want the member to be called (which normally defaults to this when calling a member function directly with its name).
The syntax for this is quite strange. It requires another pair of parentheses and depends on wether you call it on a pointer or an object itself:
(object.*functionPointer)(arguments);
(pointer->*functionPointer)(arguments);
So if you just want to call the function on the this pointer, you need to write
(this->*fkt)(rhoRef, yRef);
(Note that you don't need to specify the class in your code everywhere. Amrorder:: can be removed in front of every function name inside the definition of a member function of the same class.)
When you call a non-static method of a class, the compiler needs to know which instance of the class you want to execute against. So there is a hidden parameter in the call, which is a pointer to the instance.
So you need to write something like this:
Amrorder::fkt=bind( &Amrorder::fktAcPulse, this );

Troubles with pointer to methods

I'm just learning C++ and I'm having difficulties regarding pointers to methods. Lets say:
class One {
public:
int Add (int a, int b) {return a+b;}
};
typedef int (One::*pAdd) (int, int);
class Other {
public:
int Next (pAdd funct, int c){ return funct (c, 1);}
};
int main (){
One one;
Other other;
other.Next(one.Add, 2);
return 0;
}
I have a number of problems, as reported by my MinGW. First, I'm not invoking funct correctly, as compiler insists on using .* or ->* . Have no idea how to incorporate this request and any help is welcomed. Now, I could solve my problems by making methods static to use c-style pointers or pass objects and invoke methods from within Next, but I want to understand pointers to methods. Basically, I'm puzzled why one.Add is not an acceptable input. Method to call is unambiguously defined (.Add) and conforms my typedef. Also, I'm providing instance of class (one) from typedef thus providing context in which method is to be executed. But compiler output looks like I didn't only miss the syntax, but like I missed the concept. So, how to pass pointer to method with object as context as a single argument?
The main problem here is that member functions are not associated with an object instance, they are just function pointers with a slightly different signature.
So, when you want to call a member function you need two things: a pointer to the member function and the object instance in which to call it.
I changed your code sample a bit:
#include <iostream>
class One {
public:
int Add (int a, int b) {return a+b;}
};
typedef int (One::*pAdd) (int, int);
class Other {
public:
int Next (One one, pAdd funct, int c){
return (one.*funct)(c, 1);
}
};
int main (){
One one;
Other other;
std::cout << other.Next(one, &One::Add, 2) << std::endl;
return 0;
}
And it works now. It can probably be improved a bit, but I think you can take it from here.
I recommend that you read Pointers to member functions section of the c++ faq lite, which explains this very well.
So, how to pass pointer to method with object as context as a single argument?
Using just member-function pointers, you can't. Although your syntax looks like something that should do that, it just isn't allowed. You need an object to apply the function to:
class Other {
public:
int Next (pAdd funct, One & o, int c){ return (o.*funct) (c, 1);}
}
int main (){
One one;
Other other;
other.Next(&One::Add, one, 2);
}
If you want to create a function object that calls a particular member function of a particular object, then one possibility is to use std::bind (or boost::bind if you can't use C++11 yet):
#include <functional>
class Other {
public:
int Next (std::function<int(int,int)> funct, int c){ return funct (c, 1);}
};
int main (){
One one;
Other other;
using namespace std::placeholders;
other.Next(std::bind(&One::Add, &one, _1, _2), 2);
}
or a lambda:
other.Next([&](int a, int b){return one.Add(a,b);}, 2);
Pointers to members need an instance to operate on. Essentially, they are functions which take an addition parameter which becomes the implicit this pointer. To call a function through a pointer to member for the current object you can use code like this:
(this->*funct)(c, 1);
(you'd access member variables similarly but without a function call).
The object you call the member on isn't part of the pointer to member. As a result you need to get it something like this:
&One::Add
This becomes more interesting if the member function is overloaded: in this case you need to provide a context from which the overload can be determined when taking the address. I tupically use a static_cast<>() for this:
static_cast<int (One::*)(int,int)>(&One::Add)
You have a bunch of problems here: one.Add is a member function and
you cannot just invoke it. You need to have a pointer to the class to
invoke it on as well. Also, you need to use the special operator.*
or operator->*. You can also not take the address of a bound member
function.
All in all, you should use a template and boost/std::bind to make
all this bearable or stay away from it.
Here is modified, working code:
class One {
public:
int Add (int a, int b) {return a+b;}
};
typedef int (One::*pAdd) (int, int);
class Other {
public:
int Next (One* one, pAdd funct, int c){ return (one->*funct)(c, 1);}
};
int main (){
One one;
Other other;
other.Next(&one, &One::Add, 2);
return 0;
}

C++: Function pointer to another class function

I have 2 classes
class B {
public:
int func(int i);
};
class A {
public:
typedef int (B::*fPtr)(int);
void run();
B* mB;
};
void A::run() {
// create a pointer
fPtr p = &(B::func);
// invoke the function
mB->*p(2); <------- Compilation Error
}
What i need is to create a pointer to func() in A's run function. I get a compilation error saying that mB is not corresponding to a function with 1 argument.
please help
You need to put parentheses around the function expression:
(mB->*p)(2);
But as others have pointed out, there's almost certainly a better way to do what you're trying to do.
Instance methods on a class always have a hidden first parameter for the this pointer, thus it is incompatible with your function pointer typedef. There is no way directly to obtain a pointer to a member function. The typical workaround is to use a "thunk" where you pass a static function that accepts a generic "catch all" parameter (such as void *) which can be statically cast to a pointer of your choosing on which you can invoke the member function. Example:
class B
{
public:
static void MyThunk(void * obj)
{
static_cast<B *>(obj)->MyRealFunc();
}
void MyRealFunc()
{
// do something here
}
// . . .
};
You can get a pointer to the static function easily as it has no 'hidden this', just reference it using B::MyThunk. If your function requires additional parameters, you can use something like a functor to capture the necesssary parameters and state.
You should definitely read this C++ FAQ Lite page which tells you much more about all this: Pointers to member functions
why can you not call mB->func(2);?
If you need different functions for B perhaps look into virtual functions and class inheritance

passing functor as function pointer

I'm trying to use a C library in a C++ app and have found my self in the following situation (I know my C, but I'm fairly new to C++). On the C side I have a collection of functions that takes a function pointer as their argument. On the C++ side I have objects with a functor which has the same signature as the function pointer needed by the C function. Is there any way to use the C++ functor as a function pointer to pass to the C function?
You cannot directly pass a pointer to a C++ functor object as a function pointer to C code
(or even to C++ code).
Additionally, to portably pass a callback to C code it needs to be at least declared
as an extern "C" non-member function.
At least, because some APIs require specific function call conventions and thus
additional declaration modifiers.
In many environments C and C++ have the same calling conventions and differ only
in name mangling, so any global function or static member will work.
But you still need to wrap the call to operator() in a normal function.
If your functor has no state (it is an object just to satisfy some formal
requirements etc):
class MyFunctor {
// no state
public:
MyFunctor();
int operator()(SomeType &param) const;
}
you can write a normal extern "C" function which creates the functor and executes its
operator().
extern "C" int MyFunctorInC(SomeType *param)
{
static MyFunctor my_functor;
return my_functor(*param);
}
If your functor has state, eg:
class MyFunctor {
// Some fields here;
public:
MyFunctor(/* some parameters to set state */);
int operator()(SomeType &param) const;
// + some methods to retrieve result.
}
and the C callback function takes some kind of user state parameter (usually void *):
void MyAlgorithmInC(SomeType *arr,
int (*fun)(SomeType *, void *),
void *user_state);
you can write a normal extern "C" function which casts its state parameter to
your functor object:
extern "C" int MyFunctorInC(SomeType *param, void *user_state)
{
MyFunctor *my_functor = (MyFunctor *)user_state;
return (*my_functor)(*param);
}
and use it like this:
MyFunctor my_functor(/* setup parameters */);
MyAlgorithmInC(input_data, MyFunctorInC, &my_functor);
Otherwise the only normal way to do it
(normal as in "without generating machine code at runtime" etc.)
is to use some static (global) or thread local storage to pass the functor
to an extern "C" function.
This limits what you can do with your code and is ugly but will work.
I found this "gem" using google. Apparently possible but I sure wouldn't recommend it. Direct link to example source code.
No, of course. The signature of your C function take an argument as function.
void f(void (*func)())
{
func(); // Only void f1(), void F2(), ....
}
All tricks with functors are used by template functions:
template<class Func>
void f (Func func)
{
func(); // Any functor
}
A C callback function written in C++ must be declared as an extern "C" function - so using a functor directly is out. You'll need to write some sort of wrapper function to use as that callback and have that wrapper call the functor. Of course, the callback protocol will need to have some way of passing context to the function so it can get to the functor, or the task becomes quite tricky. Most callback schemes have a way to pass context, but I've worked with some brain-dead ones that don't.
See this answer for some more details (and look in the comments for anecdotal evidence that the callback must be extern "C" and not just a static member function):
C++ Using Class Method as a Function Pointer Type
I don't think you can: operator() in a function object is really a member function, and C doesn't know anything about those.
What you should be able to use are free C++ functions, or static functions of classes.
GCC allows you to convert member function pointers to plain function pointers (the first argument of the function called by the plain function pointer then is this).
Check out the respective link in the manual.
This requires the -Wno-pmf-conversions flag in order to silence the respective warning for the decidedly non-standard feature. Very convenient for interfacing C style libraries with C++ style programming. When the member function pointer is a constant, this does not even need to generate any code at all: the API would use that argument order anyway.
If you already have a functor, flattening the functor in that manner will likely mean flattening its operator(), giving you a function that has to be called with a functor class pointer itself as its first argument. Which does not necessarily help all that much but at least has C linkage.
But at least when you are not going through functors this is helpful and provides a no-nonsense C linkage replacement for std::mem_fn from <functional>.
It depends if this is a static or instance method, if it is static then you can pass through the function as className::functionName, if it is an instance method it is fair more complicated, because you obviously need to tie to a certain instance but can't do it in the same way as you would with delegates in C# etc.
The best way I've found of doing this is to create a holding class which is instantiated with the instance of the object as well as the function pointer, the holding class can then invoke the function directly.
I would say no, because a C++ functor has an overloaded operator () which is a member function, and would thus require a member function pointer. This is a totally different data type than a normal C function pointer, since it cannot be invoked without an instance of the class. You'd need to pass a normal function or a static member function to the C library. Since an overloaded () operator can't be static, you can't do it. You'd need to pass the C-library a normal, non-member function or static member function, from which you can then invoke the C++ functor.
Hm, maybe you could write a free template function that wraps around your function-objects. If they all have the same signature, this should work. Like this (not tested):
template<class T>
int function_wrapper(int a, int b) {
T function_object_instance;
return funcion_object_instance( a, b );
}
This would do for all function that take two ints and return an int.
Many C APIs that take function pointer callbacks have a void* parameter for user state. If you've got one of those, you're in luck - you can use an exterm C function that treats the user data as some sort of reference or key to lookup the functor, then execute it.
Otherwise, no.
With C++11, you can use std::bind to solve the problem
#include <stdio.h>
#include <functional>
class aClass
{
public:
int i = 5;
aClass(int i_) : i(i_) {}
void operator()(int a, int b) {
i = i + 1;
printf ("%d + %d = %d i = %d\n", a, b, a + b + i, i);
}
};
void test (int a, int b)
{
printf ("%d - %d = %d\n", a, b, a - b);
}
template <class op>
void function1 (op function)
{
function (1, 1);
}
int
main (int argc, const char *argv[])
{
aClass a(1);
// function1 (a); // this is the wrong way of using it
using namespace std::placeholders;
std::function<void(int,int)> callback;
callback = std::bind(&aClass::operator(), &a, _1, _2);
function1 (callback);
function1 (callback);
function1 (test);
function1 (test);
return 0;
}