help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error: ambiguous overload for 'operator <<' in ...


From: John V Shahid
Subject: Re: error: ambiguous overload for 'operator <<' in ...
Date: Sat, 28 Oct 2006 04:44:11 +0000

I'm sorry that this wasn't posted early enough, but it looks like i was
trying to send it to the wrong mailing list by mistake.

If you give more information on the error that the g++ issued it would
be clearer. But in my opinion, the g++ is trying to call the same
function recursively, which with no doubt will give compilation error
since "const char *" doesn't have the members that you're trying to
access. You can check that by looking at the type of "C" in the error
message which should be in this case "const char *". Also i'm assuming
that you declared this function in "namespace std" before defining it.If
this was the case then the two candidates i know about are, first
replace your function with
namespace std
{
        template<typename iterator>
        operator<<(ostream &op, iterator begin, iterator end);
        //use iterators instead of containers
}//then define it as you did before.

The second candidate is to force the usage of the operator<< defined for
"const char*", then your call to op << "{" should be like this:

        std::template operator<<<char_traits<char> >(op, "{");

NOTE: I'm not sure from the syntax since i don't use it frequently, but
it should be more or less like this one. Also the template is used here
to eliminate the disambiguation of the compiler as it will probably
assume that your trying to compare the address of operator<< to
something called "char", and will issue an error.

if this wasn't the case feel free to reply to me.
-- 
                                                          John V. Shahid





reply via email to

[Prev in Thread] Current Thread [Next in Thread]