name-lookup

What is “Argument-Dependent Lookup” (aka ADL, or “Koenig Lookup”)?

你说的曾经没有我的故事 提交于 2019-11-25 22:17:38
问题 What are some good explanations on what argument dependent lookup is? Many people also call it Koenig Lookup as well. Preferably I\'d like to know: Why is it a good thing? Why is it a bad thing? How does it work? 回答1: Koenig Lookup , or Argument Dependent Lookup , describes how unqualified names are looked up by the compiler in C++. The C++11 standard § 3.4.2/1 states: When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered during the usual

Derived template-class access to base-class member-data

爷,独闯天下 提交于 2019-11-25 21:59:37
问题 This question is a furtherance of the one asked in this thread. Using the following class definitions: template <class T> class Foo { public: Foo (const foo_arg_t foo_arg) : _foo_arg(foo_arg) { /* do something for foo */ } T Foo_T; // either a TypeA or a TypeB - TBD foo_arg_t _foo_arg; }; template <class T> class Bar : public Foo<T> { public: Bar (const foo_arg_t bar_arg, const a_arg_t a_arg) : Foo<T>(bar_arg) // base-class initializer { Foo<T>::Foo_T = T(a_arg); } Bar (const foo_arg_t bar