0

I have a following code where I instantiate a structure in derived class which is defined in the base class. Here is the piece of dummy code that I created which gives the same error.

#include <iostream>
using namespace std;

template<class T>
class A
{
    public:
    struct t {
    int a ;
};

A() { }

virtual void xx () {    }
};

template<class T>
class B
{
     public:
     void xx() 
    {
        A<T>::t tt;
    }
};

int main() 
{
    B<int> b;
    return 0;
} 

While running the actual code I get following error at my end. identifier tt is undefined. If u run the above code it will give the error "error: need ‘typename’ before ‘A { T }::t’ because ‘A {T}’ is a dependent scope. If I use like this A {int}::t tt it works fine.

Can someone let me know how to fix this. Why I am getting this error and why my solution is working.

0 Answers0