#include<iostream>
template<int n>
class Parent
{
public:
static const unsigned int n_parent = 5 + n;
};
template<int n>
class Son : public Parent<n>
{
public:
static void foo();
static const unsigned int n_son = 8 + n;
};
template<int n>
void Son<n>::foo()
{
std::cout << "n_parent = " << n_parent << std::endl;
std::cout << "n_son = " << n_son << std::endl;
}
This piece of code will generate error
error: use of undeclared identifier 'n_parent'
I have to specify the template parameter explicitly:
template<int n>
void Son<dim>::foo()
{
std::cout << "n_parent = " << Son<n>::n_parent << std::endl;
std::cout << "n_son = " << n_son << std::endl;
}
Why the child template class can't deduce the proper scope of the inherited member implicitly?