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
13
votes
3 answers

Operator in namespace scope hiding another in global scope

Is this a compiler-bug? template T& operator++(T& t) { return t; } namespace asdf { enum Foo { }; enum Bar { }; Foo& operator++(Foo& foo); void fun() { Bar bar; ++bar; } } // end namespace asdf int main() { return…
TommiT
  • 609
  • 3
  • 9
13
votes
3 answers

Why class member functions shadow free functions with same name?

It recently came to my attention that member functions completely shadow free functions with the same name when inside the class. And by completely I mean that every free function with the same name is not considered for overload resolution at all.…
yuri kilochek
  • 12,709
  • 2
  • 32
  • 59
12
votes
1 answer

What's the meaning of the highlighted sentence below in [over.load]/1?

What is the meaning of the highlighted sentence below? Does it have anything to do with function templates? [over.load]/1: Not all function declarations can be overloaded. Those that cannot be overloaded are specified here. A program is…
Alexander
  • 2,581
  • 11
  • 17
12
votes
4 answers

Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Generator

I have a problem with the following code: Generator.h: #pragma once class Generator { public: friend class BagObject; Generator(void); ~Generator(void); ... void generator(int); private: BagObject *object; …
HeHacz
  • 131
  • 1
  • 1
  • 5
12
votes
1 answer

error determining a generic return type in C++11

In the context of a C++14 application, I use a scheme which could be resumed as follows (minimal reproducible test): template struct LocateFunctions { auto get_it() const // <-- here is the problem { auto ret = typename…
lrleon
  • 2,610
  • 3
  • 25
  • 38
12
votes
2 answers

clang/g++ difference with friend function

Why code below well compiled in g++ but get error on clang? #include class Object {}; class Print { public: template inline friend std::basic_ostream & operator<<(std::basic_ostream & out, const…
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
11
votes
1 answer

Overloading member function among multiple base classes

Basically I want to have multiple member functions with same name, but different signature, spread in multiple base classes. Example: #include struct A { void print(int) { std::cout << "Got an int!" << std::endl; } }; struct B { …
11
votes
2 answers

Ambiguous multiple inheritance of template classes

I've got a real situation which can be summarized in the following example: template< typename ListenerType > struct Notifier { void add_listener( ListenerType& ){} }; struct TimeListener{ }; struct SpaceListener{ }; struct A : public…
10
votes
2 answers

Why does this program swap the values?

I have the following code: #include "stdafx.h" #include using namespace std; #include #include #include void swap(long a, long b) { long temp; temp=a; a=b; b=temp; } int _tmain(int argc,…
ipkiss
  • 13,311
  • 33
  • 88
  • 123
10
votes
2 answers

Using fully qualified name for std namespace in C++

If name in C++ is not fully qualified, e.g. std::cout, it can lead to an unintentional error, such as mentioned at https://en.cppreference.com/w/cpp/language/qualified_lookup. But using a fully qualified name for ::std namespace, e.q. ::std::cout,…
Kam
  • 211
  • 1
  • 8
9
votes
1 answer

friend declaration of template specialization fails

The following code containing friend declaration fails with indicated error (see http://ideone.com/Kq5dy): template void foo() {} template class A { void foo(); friend void foo(); // error: variable or field 'foo'…
Gene Bushuyev
  • 5,512
  • 20
  • 19
9
votes
2 answers

Name-lookup of nested classes with inheritance

Is this guaranteed to work: struct A { struct Gold {}; }; struct B : public A { typedef Gold BaseGold; struct Gold {}; }; struct C : public B { typedef Gold BaseGold; struct Gold {}; }; static_assert(is_same
ltjax
  • 15,837
  • 3
  • 39
  • 62
9
votes
1 answer

3.4.2 Argument-dependent name lookup from n3290 Draft

A point from ISO draft n3290 section 3.4.2 paragraph 1: When the postfix-expression in a function call is an unqualified-id, other namespaces not considered during the usual unqualified lookup may be searched, and in those namespaces,…
user751747
  • 1,129
  • 1
  • 8
  • 17
9
votes
2 answers

Multiple inheritence leads to spurious ambiguous virtual function overload

In this example, classes Foo and Bar are provided from a library. My class Baz inherits from both. struct Foo { void do_stuff (int, int); }; struct Bar { virtual void do_stuff (float) = 0; }; struct Baz : public Foo, public Bar { void…
9
votes
1 answer

What is this template parsing conflict called?

I am getting an issue compiling this minimal example with g++ 7.3 template struct conflict { }; template struct s { int conflict; }; template bool go() { s* sp; return sp->conflict < 0; } The…
Nate
  • 12,499
  • 5
  • 45
  • 60
1 2
3
20 21