VC++6.0中利用友元函数进行重载时出现不能访问私有成员的解决办法
2013-12-14 17:10
453 查看
问题代码:
在vc6.0中,出现如下的错误提示:
解决办法:
#include <iostream> using namespace std; class PhoneNumber{ private: char areaCode[4]; char exchange[4]; char line[9]; public : friend istream& operator >>(istream &,PhoneNumber &); friend ostream& operator <<(ostream &,PhoneNumber &); }; istream& operator >>(istream & input,PhoneNumber &p){ input.getline(p.areaCode,4,' '); //input.ignore(); input.getline(p.exchange,4,' '); //input.ignore(); input.getline(p.line,9); return input; } ostream& operator <<(ostream& output,PhoneNumber& p){ output<<"("<<p.areaCode<<")"<<" "<<p.exchange<<"-"<<p.line<<endl; return output; } int main(){ PhoneNumber p; cin>>p; cout<<p; return 0; }
在vc6.0中,出现如下的错误提示:
解决办法:
#include <iostream> //using namespace std; //在VC6.0中运行出错 class PhoneNumber{ private: char areaCode[4]; char exchange[4]; char line[9]; public : friend std::istream& operator >>(std::istream &,PhoneNumber &); friend std::ostream& operator <<(std::ostream &,PhoneNumber &); }; std::istream& operator >>(std::istream & input,PhoneNumber &p){ input.getline(p.areaCode,4,' '); //input.ignore(); input.getline(p.exchange,4,' '); //input.ignore(); input.getline(p.line,9); return input; } std::ostream& operator <<(std::ostream& output,PhoneNumber& p){ output<<"("<<p.areaCode<<")"<<" "<<p.exchange<<"-"<<p.line<<std::endl; return output; } int main(){ PhoneNumber p; std::cin>>p; std::cout<<p; return 0; }
相关文章推荐
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法(VC6.0的bug)
- VC6_0中友元函数无法访问类私有成员的解决办法---VC6_0的经典bug(转)
- VC6.0中友元函数无法访问类私有成员的解决办法-------VC6.0的bug
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6_0中友元函数无法访问类私有成员的解决办法---VC6_0的经典bug(转)
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法-------VC6.0的bug
- VC6.0中友元函数无法访问类私有成员的解决办法
- VC6.0中友元函数无法访问类私有成员的解决办法
- 在使用SSIS设计脚本时候,出现的在PostExecute之外不能锁定变量集合进行读写访问的问题的解决
- Android 4.x 在 https 协议下无法利用 okhttp 进行网络访问的临时解决办法
- Ubuntu不能利用ssh进行远程连接的解决方案及其解决过程中出现的问题
- 利用pl/sql developer进行远程连接oracle server出现的问题及解决办法
- wordpress 固定链接设置后 出现404错误,不能访问文章的解决办法
- 在本机部署的dedecms网站上传到空间后出现首页不能访问的解决办法