It is inherited. However, the standard says that unqualified names in a template are generally non-dependent and must be looked up when the template is defined. Since the definition of a dependent base class is not known at that time (there may be specialisations of the base class template that have not yet been seen), unqualified names are never resolved to members of the dependent base class. Where names in the template are supposed to refer to base class members or to indirect base classes, they can either be made dependent by qualifying them or brought into the template's scope with a using-declaration. In the example, this could be achieved by replacing the call to base_func() with this->base_func() or base<T>::base_func(), or by adding the declaration using base<T>::base_func;.
C++
Topic: Templates
My compiler says that a member of a base class template is not defined in a derived class template. Why is it not inherited? template<typename T>class base {public: void base_func();};template<typename T>class derived : public base<T> {public: void derived_func() { base_func(); // error: base_func not defined }};
Browse random answers:
What is a template?
Can we have "Virtual Constructors"?
How can you force instantiation of a template?
What is namespace?
When is a template a better solution than a base class?
How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?
What is a friend function & its advantage?
Differentiate between a template class and class template?
What is the Standard Template Library (STL)?
When is a template a better solution than a base class?
What are the Function templates ?
What are Class templates ?
Explain about Template specialization ?
Explain about Non-type parameters for templates ?
Explain the Templates and multiple-file projects ?
What are the syntax and semantics for a function template?
Differentiate between a template class and class template.
My compiler says that a member of a base class template is not defined in a derived class template. Why is it not inherited? template<typename T>class base {public: void base_func();};template<typename T>class derived : public base<T> {public: void derived_func() { base_func(); // error: base_func not defined }};
Is it possible to specialise a member function of a class template without specialising the whole template?
Why do I need to add "template" and "typename" in the bodies of template definitions?
Is there a difference between a function template and a template function, or between a class template and a template class?