Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Invoker;
- class X;
- typedef void (*printerType)(X*, int);
- class X
- {
- private:
- int b;
- static void printsum(X* instance, int a)
- {
- cout << a + instance->b << endl;
- }
- public:
- X* setb(int b)
- {
- this->b = b;
- return this;
- }
- Invoker* getPrinter()
- {
- Invoker i;
- i.instance = this;
- i.func = (printerType)printsum;
- return new Invoker(i);
- }
- };
- struct Invoker
- {
- X* instance;
- void (*func)(X*, int);
- void Invoke(int a)
- {
- func(instance, a);
- }
- };
- int main()
- {
- X* obj = new X;
- obj->setb(5)->getPrinter()->Invoke(5);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement