VC6.0中友元函数无法访问类私有成员的解决办法-------VC6.0的bug

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

举个例子:

 

  1. #include<iostream>
  2. using namespace std;
  3. class cylinder
  4. {
  5.     friend istream operator>>(istream& is,cylinder &cy);
  6. public:    
  7.     inline double square()
  8.     {       return length*(width+height)*2+width*height*2;    }
  9.     inline double volume()
  10.     {      return length*width*height;      }
  11. private:
  12.     double length;
  13.     double width;
  14.     double height;
  15. };
  16. istream operator>>(istream is,cylinder &cy)
  17. {
  18.     cout<<"input length:"<<endl;
  19.     is>>cy.length;
  20.     cout<<"input width:"<<endl;
  21.     is>>cy.width;
  22.     cout<<"input height:"<<endl;
  23.     is>>cy.height;
  24.     return is;
  25. }
  26. int m
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值