工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 1986|回复: 4

奇怪的operator<<

[复制链接]
发表于 2008-5-15 21:09 | 显示全部楼层 |阅读模式
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. class sales_item
  5. {
  6. public:
  7. sales_item(){in = "in ";out = "out";} //default construct function
  8. ~sales_item(){}//destory function
  9. friend ostream& operator<<(ostream&, sales_item&);
  10. void display();
  11. private:
  12. string in;
  13. string out;
  14. };

  15. void sales_item::display()
  16. {
  17. cout<<in<<" *** "<<out<<endl;
  18. }
  19. //重载>>操作符
  20. ostream& operator<<(ostream& os, sales_item& item)
  21. {
  22. os<<item.in<<item.out<<endl;
  23. return ostream;
  24. }
  25. int main(int argv, char** argc)
  26. {
  27. sales_item item;
  28. item.display();
  29. return 0;
  30. }
复制代码

编译的时候提示:'ostream' : illegal use of this type as an expression
编译工具:vc6.0 ,今天中午打上了SP5。
 楼主| 发表于 2008-5-15 21:22 | 显示全部楼层
晕死,刚才再看了一下,才知道打错了返回值,应该是:return os;才对,汗……太粗心了。
回复

使用道具 举报

发表于 2008-5-15 23:04 | 显示全部楼层
错误提示是一个很重要的信息..
回复

使用道具 举报

发表于 2008-5-25 08:52 | 显示全部楼层
百分之九十以上的错误都是自己的大意
回复

使用道具 举报

发表于 2008-5-25 09:01 | 显示全部楼层
百分之九十以上的错误都是自己的大意
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2024-5-16 12:04

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表