Maestro
Maestro

Reputation: 2572

C++ primer 5th ed templates dependent and non-dependent names

In C++ Primer 5th edition Chapter16 on templates:

"It is up to the provider of a template to ensure that all names that do not depend on a template parameter are visible when the template is used. Moreover, the template provider must ensure that the definition of the template, including the definitions of the members of a class template, are visible when the template is instantiated."

But I think it is a mistake here: AFAIK non-dependent names on template parameter must be visible when the template is defined and not when "used".

Am I correct?

Here is my example:

template <typename T>
void foo(const T& )
{
    bar(); // non-dependent name
    void do_it(T); // dependent name
}

int main(){}

So the code should fail to compile although I didn't instantiate foo but doesn't complain about declaration of do_it as long as being a dependent name.

So is this a typo n the book?

Upvotes: 1

Views: 46

Answers (0)

Related Questions