name-lookup

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

倾然丶 夕夏残阳落幕 提交于 2019-12-05 22:05:09
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 reimplement this operator. Some other class uses derived classes for some work and make use of their operator

When does overload resolution of non-dependent name take place, in definition context or point of instantiation?

怎甘沉沦 提交于 2019-12-05 12:23:41
3.4 [basic.lookup]/p1 Overload resolution (13.3) takes place after name lookup has succeeded. void g(long); void g(int, int); template<class T> void f() { g(0); } void g(int, int = 0) {} int main(){ f<int>(); } gcc compiles succeed, clang faild. When does overload resolution of non-dependent name take place, in definition context or point of instantiation? Or both are right? In both context. [temp.res] 14.6\8 If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill

Why does C++11 not support name lookup like this? [closed]

♀尐吖头ヾ 提交于 2019-12-05 10:22:46
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . struct A { enum InnerEnum { X }; A(InnerEnum x) {} }; int main() { A a(X); } The compiler complains: error C2065: 'X' : undeclared identifier The compiler knows what the constructor's parameter type is, so when I pass X as the argument,

3.4.2 Argument-dependent name lookup from n3290 Draft

僤鯓⒐⒋嵵緔 提交于 2019-12-05 02:25:56
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 modifications to the search depend on the types of the arguments / template template arguments /

Erroneous private base class inaccessible?

拜拜、爱过 提交于 2019-12-04 23:24:26
问题 Compiling this code using g++ 4.2.1: struct S { }; template<typename T> struct ST { }; template<typename BaseType> class ref_count : private BaseType { }; template<typename RefCountType> class rep_base : public RefCountType { }; class wrap_rep : public rep_base<ref_count<S> > { typedef rep_base<ref_count<S> > base_type; // line 11 }; I get: bug.cpp:1: error: ‘struct S’ is inaccessible bug.cpp:11: error: within this context However, if I change the wrap_rep class to use ST : class wrap_rep :

Name lookup Clarification

巧了我就是萌 提交于 2019-12-04 17:51:39
$10.2/4- "[ Note: Looking up a name in an elaborated-type-specifier (3.4.4) or base-specifier (Clause 10), for instance, ignores all nontype declarations, while looking up a name in a nested-name-specifier (3.4.3) ignores function, variable, and enumerator declarations." I have found this statement to be very confusing in this section while describing about name lookup. void S(){} struct S{ S(){cout << 1;} void f(){} static const int x = 0; }; int main(){ struct S *p = new struct ::S; // here ::S refers to type p->::S::f(); S::x; // base specifier, ignores the function declaration 'S' ::S(); /

Operator in namespace scope hiding another in global scope

≯℡__Kan透↙ 提交于 2019-12-04 17:04:09
问题 Is this a compiler-bug? template <typename T> 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 0; } The GCC 4.7 error message is: error: no match for 'operator++' in '++bar' note: candidate is: note: asdf::Foo& asdf::operator++(asdf::Foo&) note: no known conversion for argument 1 from 'asdf::Bar' to 'asdf::Foo&' It compiles if you comment out the line: Foo&

hiding of template parameter of member template

Deadly 提交于 2019-12-04 10:25:41
问题 from temp.local : In the definition of a member of a class template that appears outside of the class template definition, the name of a member of the class template hides the name of a template-parameter of any enclosing class templates ( but not a template-parameter of the member if the member is a class or function template ). [ Example: template<class T> struct A { struct B { /* ... */ }; typedef void C; void f(); template<class U> void g(U); }; template<class B> void A<B>::f() { B b; //

Name lookup for overloaded functions defined later

落爺英雄遲暮 提交于 2019-12-04 07:28:35
I noticed strange behavior regarding function lookup when relying on a function to be defined later: #include <iostream> template <typename T> void foo(const T&) { std::cout << "Basic" << std::endl; } template <typename T> void bar() { T x; foo(x); } void foo(const int& x) { std::cout << "int:" << x << std::endl; } int main() { bar<int>(); } Output: Basic For some reason, I expected the use of foo inside bar to find the overload below it. Moving the overload of foo to above bar makes the output the desired int:0 (or just writing a declaration). This same behavior does not appear to apply to

Name hiding by using declaration

天大地大妈咪最大 提交于 2019-12-03 20:22:25
#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 because there is no usable swap function with two parameters in class H . I have a question here. In my