I am trying to inherit a partially specialised template class from another partially specialised template class. I really appreciate if any one can explain what is the problem.
Example:
template<typename T, typename U>
class Base
{
public:
int i;
Base(int _i) : i{_i}
{}
};
template<typename T, typename U>
class Derived: public Base<T, U>
{
public:
Derived(int _i) :Base<T, U>{_i}
{}
};
template<typename U>
class Base<int, U>
{
public:
int i ;
Base<int, U>(int _i)
:i{_i}
{}
};
template<typename U>
class Derived<int, U>: public Base<int, U>
{
public:
Derived(int _i)
: Base<int, U>{_i}
{}
void print_i()
{
std::cout << i << std::endl;
}
};
int main()
{
Derived<int, bool> X(10);
X.print_i();
return 0;
}
Expectation: I expected that I can access the Base class member variable from a Derived class member function of the same type.
Current Output: Compile time error says: use of undeclared identifier 'i'