为什么不能用类的私有数据成员呢
#include "stdafx.h"
#include<iostream>
using namespace std;
struct stu
{
char name[20];
char num[10];
char sex[4];
int age;
};
class student
{
private:
stu st;
public:
friend ostream& operator << (ostream&,student&);
};
ostream& operator << (ostream& os,student& ob)
{
os << ob.st.num<<endl;
os << ob.st.name<<endl;
os << ob.st.sex<<endl;
os << ob.st.age<<endl;
return os;
}
int main()
{
ostream& operator << (ostream& os,student& ob);
return 0;
}
出错信息:
error C2248: 'st' : cannot access private member declared in class 'student'
书上也是这么写的呀,怎样解是这个问题呢?恳请高手指教