fork download
  1. #include <iostream>
  2.  
  3. template <class T>
  4. class BASE
  5. {
  6. protected:
  7.  
  8. T DATA;
  9.  
  10. public:
  11.  
  12. BASE()
  13. {
  14. DATA = 10;
  15. }
  16. ~BASE(){}
  17.  
  18. };
  19. template <class T>
  20. class A : public virtual BASE<T>
  21. {
  22. public:
  23.  
  24. A(){}
  25. ~A(){}
  26.  
  27. };
  28. template <class T>
  29. class B : public virtual BASE<T>
  30. {
  31. public:
  32.  
  33. B(){}
  34. ~B(){}
  35.  
  36. };
  37. template <class T>
  38. class C: public A<T>, public B<T>
  39. {
  40.  
  41. public:
  42.  
  43. C(){}
  44. ~C(){}
  45. T getDATA()
  46. {
  47. return DATA;
  48. }
  49. };
  50. int main()
  51. {
  52. C<int> c;
  53. std::cout<<c.getDATA()<<std::endl;
  54.  
  55. return 0;
  56. }
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘T C<T>::getDATA()’:
prog.cpp:47:24: error: ‘DATA’ was not declared in this scope
                 return DATA;
                        ^
prog.cpp: In member function ‘T C<T>::getDATA() [with T = int]’:
prog.cpp:48:9: warning: control reaches end of non-void function [-Wreturn-type]
         }
         ^
stdout
Standard output is empty