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 6761729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:13:35+00:00 2026-05-26T14:13:35+00:00

I have two libraries, one of which depends on the other. The first library

  • 0

I have two libraries, one of which depends on the other. The first library defines some enumerations and provides an operator<<() that prints a short chunk of text for each enumeration. I have unit tests proving that this works.

The second library, which depends on the first, passes an enumeration value to std::cout (std::ostringstream behaves the same) and gets the corresponding numerical value rather than the text. No templated code is involved so it’s not a template vs overload issue. I’ve looked through the preprocessor output to verify that the correct definitions are visible. I’m using g++ 4.1.2.

I’m unable to reproduce the problem outside of my libraries (which are thousands of lines), so I can’t post any example code. My attempt to produce example code also convinces me that I understand how this is supposed to work. I’m guessing that something included in one of the headers is causing the compiler to make a different choice when selecting which operator<< to use.

My Question: How can I get insight into what choices the compiler has in choosing which version of the operator to use and why it picked the standard one over mine.

Edit: Adding signatures as requested:
Note though that this simplified example does not exhibit the problem.

Header from the first library:

namespace utcp {
  enum GainType {AGC_GAIN_MODE, MAN_GAIN_MODE };
}

// I've tried this passing the argument by value as well.
inline std::ostream& operator<<(std::ostream &os, const hdr::GainType &val)
{...}

Code from the second libary

std::cout << "Gain Text: " << hdr::AGC_GAIN_MODE << std::endl;
  • 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-26T14:13:36+00:00Added an answer on May 26, 2026 at 2:13 pm

    The problem is, as one of the comments mentions an Argument Dependent Lookup problem. When the compiler performs lookup for std::cout << my_enum_variable it will look in the current namespace, in the std namespace and the namespace where the type of my_enum_variable is defined. Only if there is no candidate, it will go up and search the enclosing namespaces. In this case, because any enum is implicitly convertible to int it will apply that conversion and not look in enclosing namespaces. The using directive does not help there.

    The simple solution is moving the overloaded operator<< into the same namespace that the enumeration:

    namespace utcp {
      enum GainType {AGC_GAIN_MODE, MAN_GAIN_MODE };
      inline std::ostream& operator<<(std::ostream &os, const GainType &val) {...}
    }
    

    This should enable ADL to pick you overload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script which includes one or two other libraries it depends
Let's say that I have two libraries (A and B), and each has one
I have two different libGL libraries on the same Ubuntu 11.04 machine. One library
I have a project that uses two third party libraries, both of which make
I have a Clojure main application that depends on several Clojure libraries, two of
We have two projects that are both class libraries. Project 1 is a VS
I have a project that uses two independent Android libraries. Each of them contains
In my project I have two libraries that would currently result in a circular
I am developing a library, which provides some time consuming services. I need to
I have a situation where I am using two libraries which have duplicate header

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.