VC++这方面的确存在问题,楼上两位的VC++都没问题吗?
程序代码:
#include <iostream>
using namespace std;
class Node{
int x;
public:
Node(){}
Node(int n){x=n;}
friend ostream& operator << (ostream& o, const Node& n);
};
ostream& operator << (ostream& o, const Node& n)
{
return o<<n.x;
}
int main()
{
Node x(123);
cout<<x<<endl;
//system("pause");
}
以上这段完全没问题的代码在VC++中就通不过
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
D:\My Documents\我的C++工程\temp\main.cpp(14) : error C2248: 'x' : cannot access private member declared in class 'Node'
D:\My Documents\我的C++工程\temp\main.cpp(5) : see declaration of 'x'
D:\My Documents\我的C++工程\temp\main.cpp(20) : error C2593: 'operator <<' is ambiguous
D:\My Documents\我的C++工程\temp\main.cpp(22) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
main.obj - 2 error(s), 1 warning(s)