我来我网
https://5come5.cn
 
您尚未 登录  注册 | 菠菜 | 软件站 | 音乐站 | 邮箱1 | 邮箱2 | 风格选择 | 更多 » 
 

minmin





性别: 美女 状态: 该用户目前不在线
等级: 栋梁之材
发贴: 615
威望: 0
浮云: 1229
在线等级:
注册时间: 2007-09-16
最后登陆: 2008-06-30

5come5帮你背单词 [ magnet /'mægnit/ n. 磁体,吸引人的人或物 ]


友元函数

书上不是说友元函数可以访问类的私有成员嘛..可是我的程序为什么出错了...denom,numer是类的私有成员
friend ostream & operator << (ostream & out,const Rational & value){
    if(value.denom!=0){
        out<<value.numer;
        if(value.denom!=1){
            out<<'/'<<value.denom;
            return out;
        }

        if(value.numer==0)
            out<<"indeterminate";
        else{
            if(value.numer<=0)
                out<<'-';
            out<<"infinity";
        }
        return out;
    }
}



error C2248: 'denom' : cannot access private member declared in class 'Rational'
        e:\programmer\visual c++\rationals\rational.h(20) : see declaration of 'denom'
E:\programmer\Visual C++\Rationals\Rational.cpp(94) : error C2248: 'numer' : cannot access private member declared in class 'Rational'
        e:\programmer\visual c++\rationals\rational.h(19) : see declaration of 'numer'
E:\programmer\Visual C++\Rationals\Rational.cpp(95) : error C2248: 'denom' : cannot access private member declared in class 'Rational'
        e:\programmer\visual c++\rationals\rational.h(20) : see declaration of 'denom'
E:\programmer\Visual C++\Rationals\Rational.cpp(96) : error C2248: 'denom' : cannot access private member declared in class 'Rational'
        e:\programmer\visual c++\rationals\rational.h(20) : see declaration of 'denom'
E:\programmer\Visual C++\Rationals\Rational.cpp(100) : error C2248: 'numer' : cannot access private member declared in class 'Rational'
        e:\programmer\visual c++\rationals\rational.h(19) : see declaration of 'numer'
E:\programmer\Visual C++\Rationals\Rational.cpp(103) : error C2248: 'numer' : cannot access private member declared in class 'Rational'
        e:\programmer\visual c++\rationals\rational.h(19) : see declaration of 'numer'
Error executing cl.exe.
顶端 Posted: 2008-04-17 21:02 | [楼 主]
xys1985



性别: 帅哥 状态: 该用户目前不在线
等级: 品行端正
发贴: 122
威望: 0
浮云: 1108
在线等级:
注册时间: 2006-10-03
最后登陆: 2010-06-13

5come5帮你背单词 [ cabin /'kæbin/ n. 船舱,机舱,小木屋 ]


我记得友元函数基本上是在类的内部声明,而在外部定义的普通函数见多..
顶端 Posted: 2008-04-17 21:10 | [1 楼]
我来我网·5come5 Forum » 程序员之家

Total 0.008861(s) query 6, Time now is:11-22 04:57, Gzip enabled
Powered by PHPWind v5.3, Localized by 5come5 Tech Team, 黔ICP备16009856号