fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Test2;
  6.  
  7. class Test1
  8. {
  9. public:
  10. Test1(){}
  11. operator Test2();
  12. };
  13.  
  14. class Test2
  15. {
  16. public:
  17. Test2(){}
  18. Test1 operator[] (const Test2& test2){ return Test1(); }
  19. friend ostream& operator << (ostream& os, const Test2& test2); // изменение здесь
  20. };
  21.  
  22. ostream& operator << (ostream& os, const Test2& test2){ return os; } // и здесь
  23.  
  24. Test1::operator Test2(){ return Test2(); }
  25.  
  26. int main()
  27. {
  28. Test2 test2_1, test2_2;
  29. cout << test2_1[test2_2] << endl;
  30. return 0;
  31. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout