fork download
  1. template<typename T>
  2. class C;
  3.  
  4. template<typename T>
  5. class CBase
  6. {
  7. private:
  8. int foo;
  9. friend class C<T>;
  10. };
  11.  
  12. template <typename T>
  13. class C : public CBase<T>
  14. {
  15. using CBase<T>::foo;
  16. public:
  17. void access() { foo = 1; } // есть везде, кроме T = int
  18. };
  19.  
  20. template <>
  21. class C<int> : public CBase<int>
  22. {
  23. using CBase<int>::foo;
  24. public:
  25. void funct() { foo = 42; } // есть только для T = int
  26. };
  27.  
  28. int main()
  29. {
  30. C<void> cv;
  31. cv.funct();
  32. C<int> ci;
  33. ci.access();
  34. return 0;
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:31: error: ‘class C<void>’ has no member named ‘funct’
prog.cpp:33: error: ‘class C<int>’ has no member named ‘access’
stdout
Standard output is empty