I have a class within which an object of another class is declared (composition). The first contains a method, a pointer to which you want to pass to the second class constructor. It turned out. How then to call a method on the pointer? In reality, several objects of different classes are declared inside the class. There is one function to use in some of the inner classes. Therefore, trying to figure out how to do it. I try to transfer the pointer to it.
header file
class CharScreen; // класс внутри которого будет объявлен объект Loader class Loader { private: void (CharScreen::* Conv)(uint8_t index); // указатель на метод public: Loader(void (CharScreen::* Convertor)(uint8_t index)); void CalculateMenuSize(); // метод внутри которого нужно сделать // вызов, переданного в конструктор // метода, по указателю }; class CharScreen { private: Loader Loader; // объявляю объект Loader public: CharScreen(); void ConvertVar(uint8_t index); // тот самый метод, который нужно // передать в конструктор Loader }; cpp
Loader::Loader(void (CharScreen::* Convertor)(uint8_t index)): { Conv = Convertor; // присваиваю объявленному в заголовке указателю, // преданный в конструктор параметр-указатель на метод } void Loader::CalculateMenuSize() { (*Conv)(1); // вот здесь возникает проблема "operand of "*" must be a // pointer" } CharScreen::CharScreen(): Loader(&CharScreen::ConvertVar) { Loader.CalculateMenuSize(); } void CharScreen::ConvertVar(uint8_t index) { }