M
michael.alexeev
Hi all,
Consider the following program:
template <class T>
struct Traits{
typedef typename T::type_t type_t; //line 3
};
template <class Derived>
struct Base{
typedef typename Traits<Derived>::type_t type_t; // line 8
type_t foo() {
Derived& self = static_cast<Derived&>(*this);
return self.bar();
}
};
template<typename T>
struct Derived : public Base<Derived<T> >{
typedef T type_t;
type_t bar() {
return type_t();
}
};
int main(){
Derived<int> d;
return 0;
}
Compiler (gcc 4.0.2) complains with the following message:
t.cxx: In instantiation of Traits<Derived<int> >:
t.cxx:8: instantiated from Base<Derived<int> >
t.cxx:17: instantiated from Derived<int>
t.cxx:25: instantiated from here
t.cxx:3: error: no type named type_t in struct Derived<int>
I was under the impresion that declarations in the Base class template
are instantiated when the Derived class is declared which means that
Derived::type_t is accessable. Looks like it's not a case.
Any help/walkaround is greatly appreciated.
Mike
Consider the following program:
template <class T>
struct Traits{
typedef typename T::type_t type_t; //line 3
};
template <class Derived>
struct Base{
typedef typename Traits<Derived>::type_t type_t; // line 8
type_t foo() {
Derived& self = static_cast<Derived&>(*this);
return self.bar();
}
};
template<typename T>
struct Derived : public Base<Derived<T> >{
typedef T type_t;
type_t bar() {
return type_t();
}
};
int main(){
Derived<int> d;
return 0;
}
Compiler (gcc 4.0.2) complains with the following message:
t.cxx: In instantiation of Traits<Derived<int> >:
t.cxx:8: instantiated from Base<Derived<int> >
t.cxx:17: instantiated from Derived<int>
t.cxx:25: instantiated from here
t.cxx:3: error: no type named type_t in struct Derived<int>
I was under the impresion that declarations in the Base class template
are instantiated when the Derived class is declared which means that
Derived::type_t is accessable. Looks like it's not a case.
Any help/walkaround is greatly appreciated.
Mike