fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class T>
  5. class myclass;
  6.  
  7. template<class T>
  8. void f(myclass<T> &c);
  9.  
  10. template<class T>
  11. class myclass
  12. {
  13. private:
  14. T value;
  15. public:
  16.  
  17. template<typename U>
  18. friend void f(myclass<U> &c);
  19. T getvalue()
  20. {
  21. return value;
  22. }
  23. void setvalue(T v)
  24. {
  25. value=v;
  26. }
  27. };
  28.  
  29. template<class T>
  30. void f(myclass<T> &c)
  31. {
  32. cout<<endl<<"function called:\n";
  33. cout<<c.getvalue()<<endl;
  34. }
  35. int main()
  36. {
  37. myclass<int> object;
  38. object.setvalue(6);
  39. f(object);
  40. return 0;
  41. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
function called:
6