VC6中重载cout的操作符<<,这样都能错误!为什么iostream就错iostream.h就不好?
#include <iostream>
using namespace std;
class CIOSTest
{
private:
friend void operator << (ostream &, CIOSTest &);
int data;
};
void operator << (ostream &os, CIOSTest &test)
{
cout<< test.data;
}
void main()
{
CIOSTest test1;
cout << test1;
}
Compiling...
复件 a1.cpp
C:\Windows\Desktop\复件 a1.cpp(13) : error C2248: 'data' : cannot access private member declared in class 'CIOSTest'
C:\Windows\Desktop\复件 a1.cpp(8) : see declaration of 'data'
C:\Windows\Desktop\复件 a1.cpp(19) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
复件 a1.exe - 2 error(s), 0 warning(s)