标题:std::ostream& operator<<(std::ostream& os, const Student stu),这个函数 ...
取消只看楼主
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
结帖率:100%
已结贴  问题点数:20 回复次数:1 
std::ostream& operator<<(std::ostream& os, const Student stu),这个函数
程序代码:
std::ostream& operator<<(std::ostream& os, const Student& stu)//只要将&去掉,下面的代码就能正常跑,可是会创建临时变量,想做成直接引用的....
{
    using std::setw;
    using std::setfill;
    os << setw(stringWeith) << setfill(' ') << stu.name//报错成员name不可访问
        << setw(numberWeith) << setfill(' ') << stu.ID
        << setw(charWeith) << setfill(' ') << stu.sex << std::endl;
    return os;
}
2016-03-23 21:15
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
得分:0 
回复 2楼 rjsp
谢谢r版主,我想到原因了,应该是我没改友元函数申明时的函数原型......

[此贴子已经被作者于2016-3-24 15:31编辑过]

2016-03-24 15:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-462834-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.265105 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved