随笔 - 2, 文章 - 0, 评论 - 3, 引用 - 0
数据加载中……

'operator <<' is ambiguous

class Time{
public:
  int hour, minute, second;
public:
  void set(int h, int m, int s){ hour=h, minute=m, second=s; }
  friend Time& operator++(Time& a);
  friend Time operator++(Time& a, int);
  friend ostream& operator<<(ostream& o, const Time& t);
};

自定义类中重载操作符后,调用时,编译提示错误:'operator <<' is ambiguous

解决方法:
VC6.0 需要先声明类和重载操作符
class Time;
ostream& operator<<(ostream& o, const Time& t);
VC 6.0 在SP3之前, 对iostream与friend有Bug, 需要patch----SP5。可能这样的错误与编译器有关吧。

posted on 2009-01-15 15:23 Robbin 阅读(3575) 评论(3)  编辑 收藏 引用 所属分类: C++BUG

评论

# re: 'operator <<' is ambiguous  回复  更多评论   

期待楼主用Trubo C++将所有C++特性重现一遍
2009-01-16 09:07 | 路人丁

# re: 'operator <<' is ambiguous  回复  更多评论   

根治方法:vc9
2009-01-17 23:21 | 陈梓瀚(vczh)

# re: 'operator <<' is ambiguous  回复  更多评论   

博主的对,谢谢了,哈哈
2009-07-06 09:58 | liudong

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理