关于友员函数

xxne2002 xxne2002 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
using namespace std;

class Score
{
friend ostream & operator<<(ostream & os, const Score & s);
private:
unsigned int num;
public:
Score():num(0){};

};


ostream & operator<<(ostream & os, const Score & s)
{
os<<s.num;
return os;
}

为什么在VC6.0下出现如下错误:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
score.cpp
C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\MYPROJECTS\test\score.cpp(17) : error C2248: 'num' : cannot access private member declared in class 'Score'
C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\MYPROJECTS\test\score.cpp(8) : see declaration of 'num'
Error executing cl.exe.

score.obj - 1 error(s), 0 warning(s)
...全文
评论 17
收藏 已收藏
分享
返回顶部
xxne2002
C++ 语言 65,214 成员 250,514 内容