#include #include #include #include #include template std::function callback; /************************************************************************************************* * */ class page { public: page(int index, std::function func); void update_page(void); int get_index(void) { return index; }; private: int index; std::function function; }; page::page(int index, std::function func) { this->index = index; this->function = func; } void page::update_page(void) { this->function(); } /************************************************************************************************* * */ class the_sub { public: the_sub(); void add_page(int index, std::function func); void update(int index); private: std::vector pages; }; the_sub::the_sub() { } void the_sub::add_page(int index, std::function func) { page tmp(index, func); pages.push_back(tmp); } void the_sub::update(int index) { for (int i = 0; i < (int)pages.size(); i++) { if (pages.at(i).get_index() == i) pages.at(i).update_page(); } } /************************************************************************************************* * */ class the_main : the_sub { public: uint8_t myAger = 12; enum {MALE, FEMALE, DIVERS} sex; the_main(); void print_something(void); void display_the_class_text(void); void add_the_page(int index); void the_update_func(void); void update(int index) { the_sub::update(index); }; private: }; the_main::the_main(void) { } void the_main::add_the_page(int index) { //std::function t = std::bind(&the_main::display_the_class_text, this); add_page(index, std::bind(&the_main::display_the_class_text, this)); } void the_main::print_something(void) { std::cout << "something more " << std::endl; } void the_main::display_the_class_text(void) { std::cout << "display the_main::text!" << std::endl; print_something(); } /************************************************************************************************* * */ void xyz(void) { std::cout << "display the text" << std::endl; } /************************************************************************************************* * */ int main(void) { the_main tm; //callback t = (callback)&tm.display_the_class_text; tm.add_the_page(0); tm.update(0); std::cout << "main" << std::endl; return 0; }