Reputation: 2329
It looks like I an inherit type aliases among classes, but not among class templates? I don't understand why this code works:
#include <iostream>
//template<typename T>
struct Test1
{
// using t1=T;
using t1=int;
};
//template<typename T>
struct Test2: public Test1//<T>
{
t1 x;
};
int main(int argc, char *argv[]) {
// Test2<int> a;
Test2 a;
a.x=5;
std::cout << a.x << std::endl;
}
and this code does not:
#include <iostream>
template<typename T>
struct Test1
{
using t1=T;
};
template<typename T>
struct Test2: public Test1<T>
{
t1 x;
};
int main(int argc, char *argv[]) {
Test2<int> a;
a.x=5;
std::cout << a.x << std::endl;
}
Do types not inherit through templates?
Upvotes: 9
Views: 4184
Reputation: 899
The following will work:
typename Test1<T>::t1 x;
and, as Xeo points out in the comments above, so does:
typename Test2::t1 x;
Upvotes: 4