Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int global_a;
- template<typename D>
- struct Base {
- int foo() {
- if (global_a)
- return global_a;
- else
- return static_cast<D*>(this)->bar();
- }
- int bar() {
- return 1;
- };
- };
- struct Derived: public Base<Derived> {
- int bar() {
- return 2;
- };
- };
- int main (void) {
- Derived d;
- global_a = 5;
- std::cout << "foo() = " << d.foo() << "\n";
- global_a = 0;
- std::cout << "foo() = " << d.foo() << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement