fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template <class T>
  7. class B
  8. {
  9. public:
  10. void outB() { cout << "dim from B is " << dim_ << endl ; }
  11. B(int dim) : dim_(dim) {}
  12. ~B() {}
  13. protected:
  14. int dim_;
  15. };
  16.  
  17. template <class T>
  18. class A : B<T>
  19. {
  20. public:
  21. using B<T>::dim_;
  22. // using B<T>::outB;
  23. void outA() { cout << "dim from A is " << dim_ << endl ; }
  24. A(int dim) : B<T>(dim) {}
  25. ~A() {}
  26. private:
  27. };
  28.  
  29.  
  30. int main(int argc, const char *argv[])
  31. {
  32. shared_ptr<A<double> > ap(new A<double>(2));
  33. ap->outA();
  34. ap->outB();
  35. return 0;
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main(int, const char**)':
prog.cpp:10:8: error: 'void B<T>::outB() [with T = double]' is inaccessible
prog.cpp:34:12: error: within this context
prog.cpp:34:12: error: 'B<double>' is not an accessible base of 'A<double>'
stdout
Standard output is empty