回复 10楼 pangding
Compiling...f13.cpp
d:\c++admin\f13.cpp(29) : error C2593: 'operator <<' is ambiguous
执行 cl.exe 时出错.
f13.obj - 1 error(s), 0 warning(s)
私有数据的访问就是说,比如我定义的类中,作如下更改,其他不变
class Date {
int year,month,day;
public:
int yearo() {return year;}
int montho() {return month;}
int dayo() {return day;}
void set(int,int,int);
void add();
bool isrun();
friend ostream& operator<<(ostream&,const Date&);
};
调试结果如下:
-------------------Configuration: f13 - Win32 Debug--------------------
Compiling...
f13.cpp
D:\c++admin\f13.cpp(18) : error C2248: 'year' : cannot access private member declared in class 'Date'
D:\c++admin\f13.cpp(5) : see declaration of 'year'
D:\c++admin\f13.cpp(18) : error C2248: 'month' : cannot access private member declared in class 'Date'
D:\c++admin\f13.cpp(5) : see declaration of 'month'
D:\c++admin\f13.cpp(18) : error C2248: 'day' : cannot access private member declared in class 'Date'
D:\c++admin\f13.cpp(5) : see declaration of 'day'
D:\c++admin\f13.cpp(29) : error C2593: 'operator <<' is ambiguous
执行 cl.exe 时出错.
f13.obj - 1 error(s), 0 warning(s)
但是钱能的书上这种对私有数据成员都是可以直接访问的。。