So I'm trying to overload the extraction operator, but I keep getting an ambiguous overload error. Here's the extraction that I'm using:

bool cc = false;
cout << CC;

And here's the overload function.

ostream& operator<< (ostream &out, bool &C1){
    if(C1) out << "A";
    if(!C1) out << "D";
    return out;
}

Any ideas why I'm getting the error?

Recommended Answers

All 3 Replies

You can't since it is already overloaded for simple types.Try using a function or explain your intent.

I want to be able to set the program so that every time I print out a bool value, it will display a character based on whether it's true or false. I could just just an if statement when I print it, but I thought maybe overloading << would be a bit easier.

It would actually be more difficult and redundant despite impossible.Try something this

std::string Bool (bool Cl)  {
   std::string Res[2]={"A","D"};
   return Res[Cl];
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.