C++面向对象总结(二)--友元函数
2016-07-15
#include<iostream>
using namespace std;
class box
{
double width;
public:
friend void printwidth(box a);
void setwidth(double wid);
};
void box::setwidth(double wid)
{
width = wid;
}
void printwidth(box a)
{
count<<"this a width is "<<a.width<<endl;//直接访问私有成员
}
int main()
{
box a;
a.setwidth(20.0);
printwidth(a);
return 0;
}