I have problem with the syntax needed to initialize a static member in a class template. Here is the code (I tried to reduce it as much as I could):
template <typename T>
struct A
{
template <typename T1>
struct B
{
static T1 b;
};
B<T> b;
typedef B<T> BT;
T val() { return b.b; }
};
template <typename T>
T A<T>::BT::b;
struct D
{
D() : d(0) {}
int d;
};
int main()
{
A<D> a;
return a.val().d;
}
With g++, the error I get is:
error: too few template-parameter-lists
Any ideas how to initialize b?
Note that I would like to keep the typedef, as in my real code, B is way more complex than that.
Change the definition of
bto the following:Notice that the typedef and
B<T1>don’t necessarily specify the same type: While the typedef relies onTbeing passed toB,B<T1>relies on the template parameterT1being passed. So you cannot use thetypedefhere to specify a definition forbinB<T1>.