c++ issue with template class inheritance

Viewed 122

I'm getting an error when compiling a code that can be trivialized as follows:

#include<iostream>

template <class T>
class A
{
    protected:
        T protectedValue;

        template<class TT>
        class insideClass
        {
            public:
                TT insideClassValue;
        };
};

template<class T>
class B : public A<T>
{
    public:
        void print(T t)
        {
            insideClass<T> ic;    // <-- the problem should be here
            ic.insideClassValue = t;
            std::cout << ic.indideClassValue << std::endl;
        };
};

int main()
{
    double v = 2.;
    B<double> b;
    b.print(v);

    return 0;
};

The compiler (g++) gives the following error:

main.C: In member function ‘void B<T>::printA()’:
main.C:23:4: error: ‘insideClass’ was not declared in this scope
main.C:23:17: error: expected primary-expression before ‘>’ token
main.C:23:19: error: ‘ic’ was not declared in this scope

I figured out that if class A is not a template class, the compilation will not give any error. I do not understand why making class A a template class results in the described error. Any idea about the reasons and how to fix the problem?

2 Answers
Related