Questions tagged [name-lookup]

Name lookup is the procedure by which a name, when encountered in a program, is associated with the declaration that introduced it.

For function names, name lookup can associate multiple declarations with the same name, and may obtain additional declarations from . Template argument deduction may also apply, and the set of declarations is passed to overload resolution, which selects the declaration that will be used. Member access rules, if applicable, are considered only after name lookup and overload resolution. For all other names (variables, namespaces, classes, etc), name lookup must produce a single declaration in order for the program to compile.

Unqualified name lookup

For an unqualified name, that is name that does not appear to the right of a scope resolution operator ::, name lookup examines the scopes as described below, until it finds at least one declaration of any kind, at which time the lookup stops and no further scopes are examined.

For the purpose of unqualified name lookup, all declarations from a namespace mentioned by a using directive are members of the namespace in which the using-directive appears.

303 questions
0
votes
0 answers

R lookup performance

I saw this post comparing the performance of different name lookup operation in R http://broadcast.oreilly.com/2010/03/lookup-performance-in-r.html Here is the result for name lookup performance using single bracket '[' on a vector. 1st row = vector…
Eric
  • 253
  • 1
  • 3
  • 7
0
votes
1 answer

Name lookup of qualified base class

Consider this code: #include namespace D { struct S { S(){std::cout << "D::S\n";} }; } struct S { S(){std::cout << "S\n";} }; struct X: D::S { X(): S() {} // (1) // X(): D::S() {} // (2) void f() { S s;…
M.M
  • 138,810
  • 21
  • 208
  • 365
0
votes
1 answer

Function , class and variable all with the same name

Why do some of these compile and some not compile? Scenario 1: compilation error 'main' : redefinition; previous definition was 'data variable' #include using namespace std; int main; int main(){ } Scenario 2: compilation error syntax…
Alok
  • 1,997
  • 2
  • 18
  • 30
0
votes
0 answers

Why are superclass typedefs in scope only when the class is not a template?

Consider the following code simplified from some iterators I was writing: #include #include #include #include struct NoTemplate:public std::iterator
Eponymous
  • 6,143
  • 4
  • 43
  • 43
0
votes
1 answer

Unqualified name lookup of the name declared into the function body

I've encountered with declaration definition : A declaration is a definition unless it declares a function without specifying the function’s body #include void foo() { printf("foo\n"); } int main() { void foo(); …
user2953119
0
votes
1 answer

Phone look up during an incoming call

I am trying to build an application similar to True Caller. When an incoming call comes my application needs to connect to the server to retrieve contact name of an incoming call number only if it's not available in client's (phone's) contacts. I…
Birudv
  • 95
  • 2
  • 8
0
votes
1 answer

Usual unqualified lookup and Argument-dependent name lookup(ADL)

For unqualified name lookup, 'Usual unqualified lookup' and 'Argument-dependent name lookup'(ADL), I cannot find in standard which one happens first ? Again as both trying to add something to the overload candidate set, the order doesn't seems to…
RoundPi
  • 5,819
  • 7
  • 49
  • 75
0
votes
2 answers

Why does the child class not see the parent's typedef struct in C++?

I ran across some C++ code recently that typedefed a struct in a parent class. However, it seemed to be unavailable in the child class, even tho it was not marked private (it was protected). I've created a minimal working example (below) below that…
Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
0
votes
2 answers

Is this name lookup in dependent base class with VC++ 2010 non-standard?

The code below does not compile on Ideone or Codepad, yielding errors like: 'X' was not declared in this scope but it does on VC++ 2010: #include #include template struct Base { …
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
-1
votes
1 answer

How does Name lookup work when using multiple inheritance in C++?

Why does the following work(I know it would not work when d.f(5)): #include #include struct A { int f(int a) { return a*a; } }; struct B : A { std::string f(std::string string) { return "Hello " + string; } }; struct Derived : B…
a a
  • 322
  • 2
  • 9
-1
votes
1 answer

Is there any way to make this C++ program error free or I have to remove one of x declared in one the inherited class

#include using namespace std; class A { public: A(){cout<<"Constructing A \n";} ~A(){cout<<"Destructinf A \n";} int x; }; class B : virtual public A { public: B(){cout<<"Constructing B \n";} …
iamut04
  • 9
  • 1
-1
votes
1 answer

C++ name lookup inconsistency for template/overloaded functions

I'm building a minimal binary parser/serializer for one of my projects and I got this error that seems inconsistent at first. I have two top functions I want to expose T parse(bytes) and bytevec serialize(T const&) and from these two templated…
petoknm
  • 11
  • 6
-1
votes
1 answer

Catching the name from a function

While trying to pass a value to a constructed, I kept getting errors about that the constructed can't accept the value, is that because of the main class ? : #include #include using std::cout; using std::endl; Class…
user14947646
-1
votes
1 answer

Placement operator new lookup

I'm very new in C++ and was confused by the following example: #include #include #include class Test{ public: enum test_type{ test1 = 0, test2, test3}; void *operator new(size_t sz, test_type t){ …
St.Antario
  • 26,175
  • 41
  • 130
  • 318
-1
votes
1 answer

How can I use a nested class from a friend function?

Just as I get one solution, I have another problem. See, I have a friend statement in my templated linked list, and I need to have it as a friend to reach my private nested Node struct. template class LL; template
user11360291
1 2 3
20
21