Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct foo {
- int a = 5;
- int b = 2;
- void print() {
- std::cout << a + b << std::endl;
- }
- };
- template <typename T>
- struct bar : T {
- void print2() {
- std::cout << T::a * T::b << std::endl;
- T::b++;
- }
- };
- template <typename Base>
- bar<Base>* extend_with_bar(Base& base) {
- return static_cast<bar<Base>*>(&base);
- }
- int main() {
- foo f;
- f.print();
- auto b = extend_with_bar(f);
- b->print2();
- b->print2();
- b->print();
- f.print();
- }
Add Comment
Please, Sign In to add comment