C ++错误C2593:'operator<<'很暧昧 [英] C++ error C2593: 'operator <<' is ambiguous

查看:86
本文介绍了C ++错误C2593:'operator<<'很暧昧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友。,



构建应用程序时,下面的语句块导致错误(错误C2593:'operator<<'是不明确的):

 ostream&  operator <<(ostream& os, const 选项& O)
{
for (Options :: const_iterator mIt = O.mPlanOptions.begin(); mIt!= O.mPlanOptions.end(); mIt ++)
os<< mIt-> first<< << mIt-> second<< ENDL;
return os;
}





如果我从os<<< mIt->>中删除mIt-> second,则无错误;第一个<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<关于错误。



谢谢。

解决方案

假设 optionvector 类提供了一个字符串强制转换运算符,你可以写一下

 os << mIt-> first<< << static_cast< string>(mIt-> second)<< endl; 





或(如果你的编译器不喜欢 static_cast 关键字)



 os<< mIt-> first<< << (字符串)mIt-> second<< ENDL; 


Hi Friends.,

The below block of statements causing error(error C2593: 'operator <<' is ambiguous) while build application:

ostream& operator <<( ostream &os, const Options& O )
{
   for(Options::const_iterator mIt = O.mPlanOptions.begin(); mIt != O.mPlanOptions.end(); mIt++)
		os << mIt->first << " " << mIt->second << endl;
	return os;
}



No error if I remove "mIt->second" from "os << mIt->first << " " << mIt->second << endl;"

As I am new to c++, can anyone explain about the error.

Thanks.

解决方案

Assuming the optionvector class provides a string cast operator, you might write

os << mIt->first << " " << static_cast<string>(mIt->second) << endl;



or (if your compiler doesn't like the static_cast keyword)

os << mIt->first << " " << (string) mIt->second << endl;


这篇关于C ++错误C2593:'operator&lt;&lt;'很暧昧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆