| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include <array>
- #include <vector>
- #include <map>
- #include <iostream>
- #include <functional>
- template <typename T>
- std::function<void(T&)> callback;
- /*************************************************************************************************
- *
- */
- class page {
- public:
- page(int index, std::function<void()> func);
- void update_page(void);
- int get_index(void) { return index; };
- private:
- int index;
- std::function<void()> function;
- };
- page::page(int index, std::function<void()> 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<void()> func);
- void update(int index);
- private:
- std::vector<page> pages;
- };
- the_sub::the_sub()
- {
- }
- void the_sub::add_page(int index, std::function<void()> 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<void(void)> 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;
- }
|