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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:43:16+00:00 2026-06-18T12:43:16+00:00

I am having trouble understanding namespaces. A.cpp: #include <iostream> namespace A { int pause

  • 0

I am having trouble understanding namespaces. A.cpp:

#include <iostream>
namespace A { int pause = 8; }
int main() {
    std::cout << A::pause << std::endl;
    return 0;
}

And it prints 8. However, now I add using namespace A and change A::pause to just pause. A.cpp:

#include <iostream>
namespace A { int pause = 8; }
using namespace A;
int main() {
    std::cout << pause << std::endl;
    return 0;
}

Now, I get the compile errors:

A.cpp: In function ‘int main()’:
A.cpp:5: error: reference to ‘pause’ is ambiguous
/usr/include/unistd.h:507: error: candidates are: int pause()
A.cpp:2: error:                 int A::pause
A.cpp:5: error: reference to ‘pause’ is ambiguous
/usr/include/unistd.h:507: error: candidates are: int pause()
A.cpp:2: error:                 int A::pause

Can someone explain what went wrong? I thought using namespace A allows me to omit the A::, similarly to how using namespace std allows you to omit std::. I tried moving the line in main()but I get the same error messages. Note, I purposefully chose the variable name pause as it apparently conflicts with the pause() declared in iostream. Any feedback is appreciated. Thanks!

  • 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-06-18T12:43:18+00:00Added an answer on June 18, 2026 at 12:43 pm

    The compiler is telling you what the problem is. It has two possible routes to resolve pause – one is via A::pause and the other is via a function pause() which is defined in <unistd.h> and exists outside any namespace. The compiler can’t decide which to use so you have to help it.

    If you chose a less generic name for your variable inside the A namespace, e.g. pause_val, you could output it without the namespace scoping

    #include <iostream>
    namespace A { int pause_val = 8; }
    using namespace A;
    int main() {
        std::cout << pause_val << std::endl;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble understanding where I went wrong with my code: #include <iostream> #include
I'm having trouble understanding how to export a package symbol to a namespace. I've
I'm having trouble understanding what this query accomplishes: DECLARE @CatalogID int INSERT [Catalog] ([Name])
I'm having trouble understanding how to namespace and instantiate an object in YUI3. In
I'm having trouble understanding why the code below #include <string> #include <vector> #include <map>
I'm having trouble understanding the behavior of the return built-in in Bash. Here is
I'm having trouble understanding following code: if (IsPostBack) { int CheckBoxIndex; ArrayList CheckBoxArray; bool
Having trouble understanding how to filter an images table by tag information in a
Having trouble understanding. With the following css : .bloc .field:nth-last-child(2){ ...some values... } and
Im having trouble understanding class relationships after being asked to research it further, would

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.