I would like to pass a function of a class as parameter of another class method.
template <typename T, const uint8_t size = 8 * sizeof(T)>
class A {
[...]
A& left(const unsigned char _char) { ... }
A& right(const unsigned char _char) { ... }
}
template <class A>
class B {
static constexpr unsigned char arr[4] = { 'A', 'C', 'G', 'T' };
[...]
public:
std::vector<A> nodes(A a, std::function<A& (const unsigned char)> roll) {
std::vector<A> array;
for (unsigned char base : bases) {
A tmp = a;
// if (member(roll(base))) array.push_back(tmp); This is one idea
if (member(a.roll(base))) array.push_back(tmp); // This is the second one
}
return array;
}
}
The method left
and right
are the method that I woult pass as parameter. These two methods I would like to pass as parameters to the nodes
method of the B
class. I suppose two possible way to do that but in both case I don't know to to that.
What is the best method to do that?