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

  • Home
  • SEARCH
  • 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 6130277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:50:23+00:00 2026-05-23T16:50:23+00:00

I made a header file sampleheader.h with following code: namespace sample_namespace { int add(int

  • 0

I made a header file sampleheader.h with following code:

namespace sample_namespace
{
    int add(int n1,int n2)
    {
        return (n1 + n2);
    }
}

Now my main.cpp file is:

#include <iostream>
#include "sampleheader.h"
using namespace std;

int add(int n1, int n2)
{
  return (n1 + n2);
}

int main(void)
{
    using namespace sample_namespace;
    //cout<<add(5,7);
}

The project is built with no warning if i leave that line commented.It is understandable because the local add() function is defined in the global scope and add() function is made visible in the scope of main(). So no name conflict happens.

However, if I remove the comments, I get the following error:

"Ambiguous call to overloaded function"

First of all there should be no name conflict at all as explained by me above (if I’m right). But, if at all there is a name conflict why is it that it is notified by compiler only when I call the function. Such type of error should be shown as soon as a name conflicts (if at all).

Any help is appreciated.

  • 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-23T16:50:23+00:00Added an answer on May 23, 2026 at 4:50 pm

    “using namespace” does not hide other implementations. What it does in this case is make it ambiguous.

    You have both sample_namespace::add and ::add with the same signature. Since you don’t explicitly say which one to use, the compiler can’t tell.

    Declaring both functions is legal and unambiguous (which is why the compiler only complains when you use the function).

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

Sidebar

Related Questions

I have a class file (header and cpp) that I made, that I want
I made a new Console Application Project in XCode, and in the main.c file,
So some reason, my .cpp file is missing it's header file. But I am
I have made some modifications to nsMediaStream.h/cpp in the Mozilla (6.0.2) code and one
I have a c++ file myCppTest.cpp which has method int myFunction(int argv, char **argc)
I'm tired of copy pasting the header into my cpp file then hacking at
I made an custom UITableView. Then I made a custom header for sections. It
I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
I made a code that translate strings to match each word from the array
The project I'm working on recently made a big effort to cleanup the code

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.