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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:35:55+00:00 2026-05-23T11:35:55+00:00

There is following code: #include <iostream> using namespace std; namespace { int funkcja() {

  • 0

There is following code:

#include <iostream>

using namespace std;

namespace
{
    int funkcja()
    {
        cout << "unnamed" << endl;
        return 0;
    }
}

int funkcja()
{
    cout << "global" << endl;
    return 0;
}

int main()
{
    ::funkcja(); //this works, it will call funkcja() from global scope
    funkcja(); //this generates an error 
    return 0;    
}

I use g++. Is there some way to call function from unnamed namespace in such situation? It is possible to call function from global scope using ::function, but how to call function from unnamed namespace? Compiler generates an error:

prog3.cpp: In function ‘int main()’:
prog3.cpp:43:17: error: call of overloaded ‘funkcja()’ is ambiguous
prog3.cpp:32:5: note: candidates are: int funkcja()
prog3.cpp:25:6: note:                 int<unnamed>::funkcja()
  • 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-23T11:35:56+00:00Added an answer on May 23, 2026 at 11:35 am

    Is there some way to call function from unnamed namespace in such situation?
    No, Not in your case.

    Anonymous/UnNamed namespaces allow variables and functions to be visible within an entire translation unit, yet not visible externally. Although entities in an unnamed namespace might have external linkage, they are effectively qualified by a name unique to their translation unit and therefore can never be seen from any other translation unit.

    This means your function funkcja inside the Unnamed Namespace is visible in the translation unit which defines a global function funkcja. This causes two same named functions defined in the global scope and thus causing the redefinition error.

    If funkcja was only present in your UnNamed Namespace then You would have been able to call it by ::funkcja as it would be in your global scope. To conclude, you can call functions in UnNamed Namespace depending on the scope in which the UnNamed Namespace is present.

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

Sidebar

Related Questions

I have the following code: #include <iostream> using namespace std; struct stud{ int roll;
i wrote the following code.... #include< iostream> #include< fstream> using namespace std; int main()
i have following code #include <iostream> #include <cstdlib> using namespace std; int main() {
I have the following code: #include <iostream> using namespace std; struct S { S(int
Please look at the following code: #include <iostream> using namespace std; class A {
For the following code: #include<iostream> #include<vector> #include<string> using namespace std; struct Test { string
I have written the following code: #include stdafx.h #include <iostream> using namespace std; double
I have the following code which works as expected: #include <iostream> using namespace std;
Conside the following sample code below: #include <iostream> using namespace std; class base {
i have following code,which does not show me anything #include <iostream> using namespace std;

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.