fork download
  1. template <typename T>
  2. class MyBase {
  3. public:
  4. MyBase();
  5. virtual ~MyBase();
  6. void addStuff(T* someStuff);
  7. protected:
  8. T* stuff;
  9. };
  10.  
  11. template <typename T>
  12. MyBase<T>::MyBase() {}
  13. template <typename T>
  14. MyBase<T>::~MyBase() {}
  15.  
  16. template <typename T>
  17. void MyBase<T>::addStuff(T* someStuff) {
  18. stuff = someStuff;
  19. }
  20.  
  21. // ---------------------
  22.  
  23. template <typename T>
  24. class MyDerived : public MyBase<T> {
  25. public:
  26. MyDerived();
  27. virtual ~MyDerived();
  28. virtual void doSomething();
  29. };
  30.  
  31. template <typename T>
  32. MyDerived<T>::MyDerived() {}
  33. template <typename T>
  34. MyDerived<T>::~MyDerived() {}
  35.  
  36. template <typename T>
  37. void MyDerived<T>::doSomething() {
  38. T* thingy = new T();
  39. addStuff(thingy); //here's the compile error. addStuff is not declared.
  40. }
  41.  
  42. int main() {
  43. MyDerived<int> m;
  44. m.doSomething();
  45. }
Success #stdin #stdout 0.01s 2852KB
stdin
Standard input is empty
stdout
Standard output is empty