#include <iostream>
using namespace std;
class Box{
private:
double width;
public:
double length;
friend void printWidth(Box box);
void setWidth(double wid);
};
void Box::setWidth(double wid){
width = wid;
}
void printWidth(Box box){
cout << "box.width:" << box.width << endl;
}
int main()
{
Box box;
box.setWidth(10.0);
printWidth(box);
return 0;
}
}
c++基本语法---友元函数
最新推荐文章于 2024-11-05 17:16:24 发布