Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends.,

The below block of statements causing error(error C2593: 'operator <<' is ambiguous) while build application:
C++
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.
Posted
Comments
CPallini 8-Sep-15 7:45am    
It all depends on the type of mIt->first (or mIt->second). Unfortunately you didn't make us know about.
willington.d 8-Sep-15 7:52am    
It showing that, the type is Class Options. The "typedef DATA::const_iterator const_iterator;" is declared inside this class.
CPallini 8-Sep-15 8:03am    
I need to know the types of mIt->first and mIt->second in order to understand better.
willington.d 8-Sep-15 8:20am    
I do not know. Tell me where to find?
Class Options
{
public: typedef DATA::const_iterator const_iterator;
}

I couldn't find any reference or anything in that.
willington.d 8-Sep-15 8:35am    
And the DATA is declared as "typedef map<string, optionvector=""> DATA;"

1 solution

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;
 
Share this answer
 
Comments
willington.d 10-Sep-15 9:28am    
Not working. Tried both but the same error is being displayed. Any other solutions???
CPallini 11-Sep-15 5:17am    
Yes, get rid of VS C++ 6.0.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900