Last active
December 19, 2015 08:29
-
-
Save lambday/5926529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class base | |
{ | |
public: | |
base():m_base(0) | |
{ | |
cout << "base created" << endl; | |
} | |
virtual void bar() = 0; | |
protected: | |
void foo() | |
{ | |
cout << "foo()" << endl; | |
} | |
int m_base; | |
}; | |
template<class T> class derived1 : public base | |
{ | |
public: | |
derived1():base() | |
{ | |
cout << "derived1 created" << endl; | |
} | |
virtual void bar() | |
{ | |
foo(); | |
cout << "bar" << endl; | |
} | |
virtual void foobar() = 0; | |
}; | |
template<class T> class derived2 : public derived1<T> | |
{ | |
public: | |
derived2():derived1<T>() | |
{ | |
cout << "derived2 created" << endl; | |
} | |
virtual void foobar() | |
{ | |
base::foo(); | |
derived1<T>::bar(); | |
cout << base::m_base << endl; // this works | |
// cout << m_base << endl; // this doesn't | |
} | |
}; | |
template class derived1<int>; | |
template class derived2<int>; | |
int main(int argc, char** argv) | |
{ | |
derived2<int>* tmp=new derived2<int>(); | |
tmp->foobar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment