Im having a problem with a typedef below, I can seem to get it right:
template <typename T>
struct myclass1 {
static const int member1 = T::GetSomeInt();
};
template <int I>
struct myclass2 {
typedef myclass1< myclass2<I> > anotherclass;
static int GetSomeInt();
};
anotherclass MyObj1; // ERROR here not instantiating the class
When I try and initialize a anotherclass object, it gives me an error.
Any idea what I am doing wrong? There seems to be a problem with my typedef.
Any help is appreciated,
Thanks
Bryan
You’re referring to
anotherclassdirectly. That name doesn’t exist at that scope. You need to declare your variable aswhere
some_intis whatever integer value you want to parameterizemyclass2with.I think you’ll also need to mark
myclass2<I>::GetSomeInt()as beingconstexprso it can be used in the initializer ofmyclass1<T>::member1.With those tweaks, the following code compiles just fine:
Note, this requires C++11 for
constexpr. If you want C++03 then I don’t think yourmyclass1<T>::member1is legal.