name-lookup

Accessing base member functions in class derived from template class [duplicate]

元气小坏坏 提交于 2020-02-02 06:10:33
问题 This question already has answers here : Why do I have to access template base class members through the this pointer? (3 answers) Closed 5 years ago . I am developing a library at my work and I have designed a complicated inheritance that includes template classes and deriving from them. My problem is that a base template class has virtual overloaded operator that takes 2 arguments and returns some value. In base class this operator is implemented and most of derived classes does not

How to make all hidden names from a base class accessible in derived one?

随声附和 提交于 2020-01-22 20:39:49
问题 Starting from this question: Pointer derived from pure virtual class(A) can't access overload method from the pure class (B) And considering this simplified code: #include <string> #include <iostream> class Abstract { public: virtual void method(int a) { std::cout << __PRETTY_FUNCTION__ << "a: " << a << std::endl; } }; class Concrete : public Abstract { public: void method(char c, std::string s) { std::cout << __PRETTY_FUNCTION__ << "c: " << c << "; s: " << s << std::endl; } }; int main() {

How to make all hidden names from a base class accessible in derived one?

不打扰是莪最后的温柔 提交于 2020-01-22 20:39:33
问题 Starting from this question: Pointer derived from pure virtual class(A) can't access overload method from the pure class (B) And considering this simplified code: #include <string> #include <iostream> class Abstract { public: virtual void method(int a) { std::cout << __PRETTY_FUNCTION__ << "a: " << a << std::endl; } }; class Concrete : public Abstract { public: void method(char c, std::string s) { std::cout << __PRETTY_FUNCTION__ << "c: " << c << "; s: " << s << std::endl; } }; int main() {

Function names in global namepsace scope cannot be found

你。 提交于 2019-12-24 06:43:54
问题 According to unqualified lookup in cppreference.com: For a name used in the definition of a function, either in its body or as part of default argument, where the function is a member of user-declared or global namespace, the block in which the name is used is searched before the use of the name, then the enclosing block is searched before the start of that block, etc, until reaching the block that is the function body. Then the namespace in which the function is declared is searched until

Declare function after template defined

风流意气都作罢 提交于 2019-12-23 20:08:08
问题 Let's say I have a template function: template <class T> void tfoo( T t ) { foo( t ); } later I want to use it with a type, so I declare/define a function and try to call it: void foo( int ); int main() { tfoo(1); } and I am getting error from g++: ‘foo’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive] foo( t ); why it cannot find void foo(int) at the point of instantiation? It is declared at that point.

Interpretation of [basic.scope.hiding]p2 when unqualified name lookup involves using-directives

大兔子大兔子 提交于 2019-12-23 12:13:26
问题 There are two types of name hiding in c++: 1) Normal name hiding: [basic.scope.hiding]p1 (http://eel.is/c++draft/basic.scope.hiding#1): A name can be hidden by an explicit declaration of that same name in a nested declarative region or derived class ([class.member.lookup]). 2) The special type of name hiding in [basic.scope.hiding]p2 (http://eel.is/c++draft/basic.scope.hiding#2): A class name ([class.name]) or enumeration name ([dcl.enum]) can be hidden by the name of a variable, data member,

Template instantiation, two-phase name lookup, different behavior with automatic deduced type

瘦欲@ 提交于 2019-12-23 09:19:49
问题 After seeing this question When is a C++ template instantiation type checked? , and wondering myself for quite some time the same thing I started to play with code to assimilate the knowledge. The answer gives clear and correct explanation. It mentions two-phase name lookup and the fact that the end of translation unit is also considered a point of instantiation for function templates. However I observed different behavior when using automatic return type deduction: This is like the original

3.4.2 Argument-dependent name lookup from n3290 Draft

霸气de小男生 提交于 2019-12-22 04:08:49
问题 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, namespace-scope friend function declarations not otherwise visible may be found. These modifications to the search depend on the types of the arguments (and for template template arguments, the namespace of the template argument). Here they said aboout "these

Name hiding by using declaration

怎甘沉沦 提交于 2019-12-21 05:35:32
问题 #include <iostream> struct H { void swap(H &rhs); }; void swap(H &, H &) { std::cout << "swap(H &t1, H &t2)" << std::endl; } void H::swap(H &rhs) { using std::swap; swap(*this, rhs); } int main(void) { H a; H b; a.swap(b); } And this is the result: swap(H &t1, H &t2) In the code above, I try to define a swap function of H . In the function void H::swap(H &rhs) , I use an using declaration to make the name std::swap visible. If there isn't an using declaration, the code cannot be compiled

Why is this call to swap() ambiguous?

扶醉桌前 提交于 2019-12-21 03:15:26
问题 The following program #include <algorithm> #include <utility> #include <memory> namespace my_namespace { template<class T> void swap(T& a, T& b) { T tmp = std::move(a); a = std::move(b); b = std::move(tmp); } template<class T, class Alloc = std::allocator<T>> class foo {}; } int main() { my_namespace::foo<int> *a, *b; using my_namespace::swap; swap(a,b); return 0; } causes both g++ and clang to issue the following compiler error on my system: $ clang -std=c++11 swap_repro.cpp -I. swap_repro