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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:05:16+00:00 2026-05-21T09:05:16+00:00

I have been writing some code with basically this structure namespace util { void

  • 0

I have been writing some code with basically this structure

namespace util {
    void read (int &);
    template <typename T>
    void read (T &);
}

void foo ();

using namespace util;

namespace { // A
    void read (MyType &, int);

    void do_something () {
        MyType t;
        int i;
        // using util::read; // B
        read (i); // C
        read (t,i); // D
    }
}

void foo () {
    do_something ();
}

At first line C wasn’t compiling unless I fully qualify it as util::read(i) or uncommented line B, but that makes line D fail.

Specialising the template util::read isn’t possible because the number of arguments is different (until C++0x).

Turning line A into namespace util isn’t an option because I don’t want to export the new read.

I could rename read(MyType&,int) but that breaks ahem style.

Is there a way to make these cross-namespace overloads work nicely? Is there a good reason that they shouldn’t?

  • 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-21T09:05:16+00:00Added an answer on May 21, 2026 at 9:05 am

    Yes, it’s hard. In fact, it’s impossible.

    The best you can do is to hide names. You’re right to employ using (B) to get around the complications that name hiding brings into the mix, when you’re also overloading functions — D should still function in this case. Please show the error you got for it.

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

Sidebar

Related Questions

I have been writing some code that detects add and removal of USB devices,
I've been writing PHP web applications for some time, and have come across very
I'm writing some optimized C code that basically runs through an array and does
Lately I've been writing some JS code using jQuery and JavaScript as it is
I have been writing code like the following enough a lot lately. I don't
I try to read a local file from server. I have been googling this
I've been considering writing my own UI framework. This is mostly because I have
For the last couple of months I have been writing an intranet site for
I understand object oriented programming, and have been writing OO programs for a long
I have been thinking of maybe writing a little tool that logs into SO

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.