Reputation: 2207
I was trying to avoid duplicating code for by having a base class with mostly static functions and members. And then I'd derive from the base class in some other classes while using the code from the base class.
#include <unordered_set>
enum struct Type
{
A = 0, B, C
};
template <Type T> struct Impl;
template <Type T> struct Base
{
typedef T Tp; // error: 'T' does not name a type
typedef Impl<T> Imp;
static std::unordered_set<Imp*> _Inst;
static void grab(Imp * ptr) { _Inst.insert(ptr); }
static void drop(Imp * ptr) { _Inst.erase(ptr); };
static void swap(Imp * ptr, Imp * old) { drop(old); grab(ptr); }
// ...
};
template <> struct Impl<Type::A> : public Base<Type::A>
{
// ...
};
template <> struct Impl<Type::B> : public Base<Type::B>
{
// ...
};
template <> struct Impl<Type::C> : public Base<Type::C>
{
// ...
};
int main(int argc, char** argv)
{
return 0;
}
The actual implementation is a lot more different than that example and requires me to have an approach similar to that.
Upvotes: 0
Views: 484
Reputation: 16737
T
isn't a type and you can only typedef
types. Create a member variable. For example,
constexpr Type Tp = T;
Upvotes: 1