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

I'm trying to create an user defined header file and suffering from an error :(

When I'm trying to compile my code, this message appears: undefined reference to `N::my_class::do_something()' collect2.exe: error: ld returned 1 exit status What can I do? my_class.cpp #include "my_class.h" // header in local directory #include…
0
votes
1 answer

C++, conflicting between library function and inhertited class function

#include #include using namespace std; class A{ public: bool close(){ return true; } }; class B: public A{ public: void fun(){ (void) close(1); } }; int main() { B b; …
R_S
  • 11
  • 3
0
votes
0 answers

Where is swift compiler's symbol table?

I wanted to know how name resolution happens in swift compiler, but I am unable to find code that is responsible for name lookup. A explanation of how name lookup happens (in swift compiler) will be a huge help. I also suspect that name lookup is…
0
votes
2 answers

no match for call to '(std::string {aka std::__cxx11::basic_string}) ()'

I am making a project in C++ and it gives the following error: in function 'int main()': Line 35; Col 12; [Error] no match for call to '(std::string {aka std::__cxx11::basic_string}) ()' This is Line 35: This is password(): int password() { …
thes_real
  • 1
  • 1
  • 1
0
votes
1 answer

Using decltype in a nested-name-specifier

Consider the following demonstrative program. #include namespace N { struct A { static int n; }; A A; } int N::A::n = 10; int main() { std::cout << N::A::n << '\n'; std::cout << N::decltype( N::A…
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0
votes
2 answers

How can I forward declare an array inside a namespace in c++

I've been trying to find out how I can use namespaces properly. I want to use a namespace, but not have to define it in the header file. I am not sure how I can do this with an array inside the namespace. I either get an "already defined symbol"…
0
votes
2 answers

Namespace method cannot be called

I cannot acces the method from File1 in File2, the message is "has not been declared". File1.cpp namespace n1 { namespace { bool method(int x) { return x; } } } File2.cpp #include…
James Dean
  • 73
  • 8
0
votes
1 answer

String lookup error for global variable in CUDA?

I have something like either: __constant__ double PNT[ NUMCOORDS ]; __device__ double PNT[ NUMCOORDS ]; depending upon some preprocessor selections. I then use this variable: cudaMemcpyToSymbol("PNT", point, pntSize) However, sometimes (and I…
tim
  • 9,896
  • 20
  • 81
  • 137
0
votes
3 answers

Global namespace friend class cannot access private member of named namespace class

In a named namespace class, I declare a class (which is in the global namespace) as friend. However, the latter class cannot access the private member of the former class. Why is this? Is there any way around it? Bob.h namespace ABC { class Bob…
didjek
  • 393
  • 5
  • 16
0
votes
0 answers

Global Dictionary and dict_items

I've been trying to understand how name lookup works in python and have been messing with the global dictionary and stumbled upon something that confused me >>> glob_dict=globals() >>> glob_items=glob_dict.items() >>> glob_list=list(glob_items) >>>…
Colin Hicks
  • 348
  • 1
  • 3
  • 13
0
votes
0 answers

Resolving a function used within a namespace-d template function

I'm observing some seemingly strange behavior when trying to instantiate a template function. In brief, I'm implementing a template function library. For the purposes of this library, I am assuming that for each type T used to instantiate one of…
0
votes
1 answer

C++: Why is name dependent in constructor, not in static member function

I have got somewhat of a follow-up question to the scenario I described here, I found this post especially helpful for reasoning about my problem. Background In my original question, I was interested in overloading the std::make_shared function to…
mutableVoid
  • 1,284
  • 2
  • 11
  • 29
0
votes
2 answers

::(scope resolution operator) preceded by nothing

what is the meaning of the :: , without preceding by anything ::flann::SearchParams param_k_; I get below errors on one project but not on another. error C2079: 'pcl::KdTreeFLANN>::param_radius_' uses…
0
votes
2 answers

How to use logger with template when using const char *?

The code in the link below doesn't work as intended. I don't know what I'm doing wrong. https://coliru.stacked-crooked.com/a/f6ac59c7c20be10c The code can be seen below, and the error message is in the link above. #include #include…
Guy Simonsen
  • 123
  • 5
0
votes
2 answers

In Python, when looking up an undefined global variable, is it possible to dynamically generate a value?

In Lua, global variables are stored in a table named _G. You can add a metatable to _G, such that when you lookup an undefined global value, a user defined function is called to provide a value. In the below example, looking up any undefined…
mpb
  • 1,277
  • 15
  • 18