C++类内重载operator<<
#include <iostream>
using namespace std;
class A {
public:
int a;
friend ostream& operator<<(ostream& os, A);
};
//友元函数定义在外部 不在某个类的作用域内
//ostream& A::operator<<(ostream& os, A A)
ostream& operator<<(ostream& os, A A) {
cout << A.a << endl;
return cout;
}
int main()
{
A a{};
cout << a;
return 0;
}