fork download
  1. #include <iostream>
  2.  
  3. template<class T>
  4. class A
  5. {
  6. public:
  7. template<class> friend class B;
  8.  
  9. explicit A(T x) : priv_(x) {}
  10.  
  11. private:
  12. T priv_;
  13. };
  14.  
  15. template<class T>
  16. class B
  17. {
  18. public:
  19. B() : a_(1) { std::cout << a_.priv_ << '\n'; }
  20.  
  21. private:
  22. A<T> a_;
  23. };
  24.  
  25. int main()
  26. {
  27. B<int> b;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1