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
1
vote
1 answer

How to interpret the rule [namespace.udir]p2 in the c++ standard?

I'm a bit confused about the implications of [namespace.udir]p2. Consider the following program: namespace X { int i = 1; } namespace Y { using namespace X; } int main() { i = 2; } In it name-lookup for i in main fails (i tried with GCC, Clang…
Supremum
  • 542
  • 7
  • 23
1
vote
3 answers

reference to array is ambiguous error when using memset function

I didn't understand why i take this "strange" error. I read similar questions but it didn't answer my questions. If i define the array inside main function rather than global scope, there is no error. But assume that i have to define this array in…
metis
  • 1,024
  • 2
  • 10
  • 26
1
vote
1 answer

Is this syntax illegal?

The following will not compile on GCC 4.8.1: //struct Tag {}; // Program compiles if I use this. template struct Base { struct Tag {}; Base(Tag) {} }; template struct Derived : Base { Derived(Tag tag) :…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
1
vote
1 answer

What is __getattr__ order in the attribute lookup chain?

So in order to get rid of some boilerplate I opted to implement __getattr__ for delegating some method calls. The problem is that I also have a descriptor in the attribute lookup chain and they are not interacting as I expected. Here's the…
David K.
  • 6,153
  • 10
  • 47
  • 78
1
vote
1 answer

usage of namespaces in libraries

I'd like to know if fully qualifying names in a library is necessary. For example (I indent namespaces here for readability): namespace A { namespace B { namespace C { class Foo { ... }; } // namespace C …
PixelRick
  • 149
  • 1
  • 8
1
vote
2 answers

Function not found from global namespace if there's an overload with different argument types

If we have a function in the global namespace and an overload with different argument types in another namespace, it seems that C++Builder compiler doesn't find the function from the global namespace. namespace A { class a { friend void…
Samuli Hynönen
  • 662
  • 1
  • 8
  • 24
1
vote
1 answer

how could I gain a class address from it's base in multiple-inheritance?

I used a third-part library in my company. In it, Some classes I need is defined like this: class A {}; class B : public A {}; class C : public A {}; class Foo : public B , public C , public A {}; And here, I need to gain offsets between Foo…
1
vote
1 answer

virtual method behaves differently with multiple inheritance

why this works struct Base { virtual void visit(const A &) { }; virtual void visit(const B &) { }; } and this complains about ambiguity when calling visit method template< typename T > struct X { virtual void visit(const T &) {…
1
vote
1 answer

Templates and name lookup with `stdio.h` functions

I'm trying to build the PCL library in a 32 bit Windows 7 with MinGW. When building the outofcore module I got several error messages about _fseeki64: error: there are no arguments to '_fseeki64' that depend on a template parameter, so a declaration…
Adri C.S.
  • 2,909
  • 5
  • 36
  • 63
1
vote
2 answers

Multiple inheritance order used in function resolution?

There was a question posted about inheritance and mixing interface classes: Multiple inheritance of interfaces in C++ Which led me to this question: Does the order of inheritance influence function resolution rules? Given: struct…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
1
vote
1 answer

Argument-dependent Name Lookup: add extra namespace to look into

I would like to exploit the ADL rules to check for the function in an extra namespace: Say we have a class X. class X { ... }; In A call X x; f(x); I'd like the compiler to look into namespace funky, that is until now unrelated to class X. But…
1
vote
3 answers

Using the this pointer in a dependent derived class template

In the example pointers/countingptr.hpp of the book C++ Templates - The Complete Guide members of the derived dependent class CountingPtr are referred to using the this pointer. Why is this necessary in this example? I'm aware that the this pointer…
Olumide
  • 5,397
  • 10
  • 55
  • 104
0
votes
1 answer

Method overloading & Method Hiding in C++

Why does the compiler not throw error in main() for p->f4(); line. As per my understanding class B hides f4() and should throw error class A { public: void f1(){} virtual void f2(){} virtual void f3(){} virtual…
0
votes
2 answers

In c++ Why and how classname::member syntax can be used for an instance member?

class Human { public: Human(string name); string getName() { return Human::name; } void setName(string name) { Human::name = name ; } private: string name; }; Human::name in getName and setName…
0
votes
1 answer

c++ : Friend function was not declared in this scope

I'm not able to call a friend function in my main program. Moreover, I have three files, my main.cpp program, a foobar.h and a foobar.cpp for the functions of my class. When I try to call the friend myClass* foobarfunction in my main.cpp program, I…
ilp
  • 21
  • 4