fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class T>
  5. class Test;
  6.  
  7.  
  8. class BeMyFriend
  9. {
  10. public:
  11. template<class T>
  12. int checkprivacy(const Test<T> areyoumyfriend)
  13. {
  14. std::cout << "lemme check " << areyoumyfriend.mything << std::endl;
  15. };
  16. BeMyFriend& operator=(const BeMyFriend& );
  17. BeMyFriend(){std::cout << "works " << std::endl;};
  18. };
  19.  
  20. template<class T>
  21. class Test
  22. {
  23. private:
  24. string mything= "here it is";
  25. public:
  26. friend T& T::operator=(const T&); //Works fine, no error
  27. friend T&::T(const T&); //error: prototype for 'BeMyFriend::BeMyFriend(const BeMyFriend&)' does not match any in class 'BeMyFriend'
  28. template<class D=T>
  29. friend int T::checkprivacy(const Test<D>);
  30.  
  31. };
  32.  
  33.  
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39. BeMyFriend yourfriend;
  40. Test<BeMyFriend> hmm;
  41. yourfriend.checkprivacy(hmm);
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 4260KB
stdin
Standard input is empty
stdout
works 
lemme check here it is