[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: error: ambiguous overload for 'operator <<' in ...
From: |
Ulrich Eckhardt |
Subject: |
Re: error: ambiguous overload for 'operator <<' in ... |
Date: |
Thu, 26 Oct 2006 22:43:44 +0200 |
User-agent: |
KNode/0.10.4 |
glen wrote:
> template<typename C>
> std::ostream& operator<< (std::ostream& op, const C& cpi )
> {
> typename C::const_iterator start( cpi.begin() );
> typename C::const_iterator end( --(cpi.end() ));
> typename C::const_iterator iter;
> op << "{";
> for (iter=start;iter!=end; ++iter){
> op<<*iter<<",";
> }
> op<<*iter<<"}";
> return op;
> };
>
> The offending lines are the
> op<<"{";
> and
> op<<"}";
Several things:
- You didn't provide a minimal example.
- You didn't provide the errormessage.
- The last semicolon is wrong.
- Your indentation is inconsistent, making it harder for the reader.
- Your code invokes undefined behaviour on an empty container.
> apparently it doesn't know what to do with a simple string
Well, anyways, your operator's signature matches _EVERYTHING_, including a
character literal.
Uli
--
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/