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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:43:12+00:00 2026-06-09T18:43:12+00:00

Suppose you have the following code namespace a{ struct S{}; //void f(int){} } namespace

  • 0

Suppose you have the following code

namespace a{
  struct S{};
  //void f(int){}
}

namespace b{
  struct T{};
}


struct X{};

void f(X){}
void f(b::T){}
void f(a::S){}



namespace a{
  void g(){

    S s;b::T t; 
    X x;
    f(x);
    f(s);
    f(t);
  }

}

int main(){
  a::g();
}

if void f(int){} is defined in namespace a (line 3 is uncommented), it shadows the later definitions of void f(b::T){} and void f(a::S){}, but not void f(X){}.
Why?

  • 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-09T18:43:13+00:00Added an answer on June 9, 2026 at 6:43 pm

    It shadows f(char) and f(int) will be called, since char can be implicitly casted to int.
    http://liveworkspace.org/code/8d7d4e0bc02fd44226921483a910a57b

    EDIT.

    There is function f(int) in namespace A. There is function f(A::S) in global namespace. We trying to call f(s) where s is A::S from function g, which is in namespace A, compiler finds, that function shall apply S (A::S), but there is no such function in namespace A, so compiler stops and give error.
    http://liveworkspace.org/code/5f989559d2609e57c8b7a655d5b1cebe

    There is function f(B::T) in global namespace. Trying to find in namespace A (f(int)) and in namespace B (since arg-type is in namespace B), nothing finded, compiler stops.
    http://liveworkspace.org/code/4ebb0374b88b29126f85038026f5e263

    There is function f(X) in global namespace, X is in global namespace, look at namespace A (f(int)) and in global namespace (find f(X)) – all is okay.
    http://liveworkspace.org/code/c9ef24db2b5355c4484aa99884601a1a

    For more information please read par 3.4.2 of C++ standard (draft n3337). or, more simply http://en.wikipedia.org/wiki/Argument-dependent_name_lookup

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

Sidebar

Related Questions

Suppose we have the following code: #include <iostream> struct A { virtual void f()
Suppose I have the following code: #include <vector> struct A { int a; int
Suppose I have the following code: namespace x{ class X{ virtual void x(){} }
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose that I have the following code: private void UpdateDB(QuoteDataSet dataSet, Strint tableName) {
Suppose we have following code defined in tester.py class Tester( object ): def method(
Suppose I have following code def foo(x:Int):Unit = { if (x == 1) println
Suppose I have the following code: void* my_alloc (size_t size) { return new char
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following code to collect all the possible combinations. abArray =

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.