One of my class member function needs other member functions as arguments. I learnt that the member function pointer or lambda expression can pass the member function to another member function. I did this in my class declaration:
class A
{
public:
void run();
private:
double objfun1();
double objfun2();
.... // and other object function added here
template <typename Callable>
fun_caller(Callable obj_call);
};
When I need to pass different object functions to fun_caller in the public function A::run(), I first define the lambda expression:
void run()
{
... //some code blocks
auto obj_call = [this](){return objfun1();};
fun_caller(obj_call);
... // some code blocks
}
The compiler reports error.
error C2297: '->*': illegal, right operand has type 'Callable'
What's wrong with my lambda expression? Thank you very much!!
The compiler reports error.Which error?std::functionand usestd::functionas the argument type.->*in the code you have shown.