I am quite new to C++, and probably I had naive problems. I know that there are other smilar questions, but are related to (seems to me) a more complex problems than mine. I am trying to make a firmware for Arduino, using C++ and I've hurt myself with the overloading errors.
I have this code define in a cpp file:
void class1::functionA(void)
{
object2.functionOfClass2(class1::functionB);
}
The class1 is initialized as:
class class1
{
public:
void functionA(void);
void functionB(void);
private:
}
And in the compilation gives
no matching function for call to 'class2::functionOfClass2(<unresolved overloaded function type>)'
Translating into the practical:
in my code I am using the Wire library inside a member function of the class1 for an Arduino library, where in the example the object2 and class2 are respectively the Wire object of class TwoWire.
I have the need to call the wire library inside a member function of my class1. This solution is a consequence of a previous lessons, in which I learnt that I cannot call a member function of class1 inside a non-member function, because the instantiation of the non-member function cannot be made since the class is not instantiated as an object yet, and the compiler has no clue on how to do this.
But calling the Wire. object inside a member function, I thought that was possible. But thinking better to it, actually, when passing the class1 member function pointer to the Wire function, the compiler cannot know what to pass to wire, and so the following is WRONG:
void class1::functionA(void)
{
Wire.onRequest(class1::functionB); //wrong
}
where the onRequest accept void (*)(void)
functions.
So trying with
void class1::functionA(void)
{
Wire.onRequest(&class1::functionB); //wrong
}
The error became:
error: no matching function for call to 'TwoWire::onRequest(void (class1::*)())' candidates are: void TwoWire::onRequest(void (*)())
There is a way to make those things work? If I say static and initializer list, am I on the right way with the right keywords?