举个例子:
- #include<iostream>
- using namespace std;
- class cylinder
- {
- friend istream operator>>(istream& is,cylinder &cy);
- public:
- inline double square()
- { return length*(width+height)*2+width*height*2; }
- inline double volume()
- { return length*width*height; }
- private:
- double length;
- double width;
- double height;
- };
- istream operator>>(istream is,cylinder &cy)
- {
- cout<<"input length:"<<endl;
- is>>cy.length;
- cout<<"input width:"<<endl;
- is>>cy.width;
- cout<<"input height:"<<endl;

本文介绍了在VC6.0编译器中遇到友元函数无法访问类私有成员的问题,提供了解决方案。通过调整包含头文件的方式,修复了因编译器bug导致的无法编译通过的错误,使得友元函数能够正确访问并输入私有变量。
最低0.47元/天 解锁文章
405

被折叠的 条评论
为什么被折叠?



