Hi
I understand using functors and the operator however I was wondering if you can have more than one method in a class that can be called as though its a function?
so if I had
Code:
class add_x {
add_x(int x) : x(x) {} //set member variable to value passed in
int operator()(int y) { return x + y; }
private:
int x;
};
then in main:
add_x adder(2); // create an instance of the functor class
int i = adder(8); // and "call" it
serial.printf("%d\n", i);
what if there was another method on add_x class called double
could I have another operator in some way that called that method double so whatever number was passed to it it doubled..?
Do I need templates for this or something?
Thanks