Skip to content

Instantly share code, notes, and snippets.

@lambday
Last active December 19, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambday/5926529 to your computer and use it in GitHub Desktop.
Save lambday/5926529 to your computer and use it in GitHub Desktop.
#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