Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:38:55+00:00 2026-05-31T07:38:55+00:00

I created my own << overload for bool because I wanted it to print

  • 0

I created my own << overload for bool because I wanted it to print true and false instead of 1 and 0. This usually works, except when I leave the namespace in which I defined this operator. In that case I get an ambiguous operator error.

error C2593: 'operator <<' is ambiguous
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ostream(206): could be 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]
c:\Dummy.h(43): or       'std::ostream &Dummy::operator <<(std::ostream &,bool)'
while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, bool)'
with
[
    _Elem=char,
    _Traits=std::char_traits<char>
]

How do I specify which namespace to take the operator from? Naively I tried Dummy::<< and Dummy::operator<< but neither worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:38:57+00:00Added an answer on May 31, 2026 at 7:38 am

    You should take a look at std::boolalpha, but to answer your original question:

    #include <iostream>
    
    namespace Dummy {
      std::ostream&
      operator<< (std::ostream& stream, bool f) {
        return stream << (f ? "7RU3" : "F4LS3");
      }
    }
    
    int
    main (int argc, char *argv[])
    {
      std::cerr      <<   true   <<  "\n";
      Dummy::operator<< (std::cerr, true);
    }
    

    output

    1
    7RU3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my own Attached Property like this: public static class LabelExtension {
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I created my own custom view that extends UIControl. This custom view has its
I've created my own UIPrintPageRenderer subclass and in my overload for DrawContentForPage(), I draw
I have created my own ControlTemplate for Button, like this: <Style x:Key=LightButtonStyle TargetType={x:Type ButtonBase}>
I created my own class that I want Core Data to use instead of
I created my own custom date picker consisting of an ASP TextBox, Button, and
I've created my own application in VB.NET that saves its documents into a file
I have created my own Tree implementation for various reasons and have come up
I've created my own signup form and creating the user using the Membership class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.