fork download
  1. template<int N>
  2. class A
  3. {
  4. template<int N2> friend class A;
  5. public:
  6. A() : i(N) {}
  7.  
  8. template<int K>
  9. void foo(A<K> other)
  10. {
  11. i = other.i; // <-- other.i is private
  12. }
  13.  
  14. private:
  15. int i;
  16. };
  17.  
  18. int main()
  19. {
  20. A<1> a1;
  21. A<2> a2;
  22. a1.foo(a2);
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 2720KB
stdin
Standard input is empty
stdout
Standard output is empty