注册 登录
编程论坛 C++教室

求visual c++完整版 可以解决友元函数的问题

wei1987 发布于 2007-12-17 20:48, 838 次点击
求visual c++完整版 可以解决友元函数的问题
4 回复
#2
aipb20072007-12-17 21:58
还没分清工具和语言哦。
#3
无缘今生2007-12-19 12:29
难道你现在用的工具不能处理友元???
#4
leeco2007-12-22 13:59
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)
#5
zjl1382007-12-24 12:42
我的也会这样!正不知怎么好,望高手指点!!!
大家都说要用#INCLUDE《IOSTREAM》这个头文件好,但处理友元好像有问题。不知是不是???在VC++6。0中!!!
1