views:

1150

answers:

2

I have a template class which has a static pointer-to-member, like this:

template<class T, T* T::*nextptr>
class Queue
{
    T* head;
    T* tail;
    static T* T::*pnext;
};

My question is how to write the initializer of the static pointer-to-member. I tried the obvious case:

template<class T, T* T::*nextptr> T* Queue<T, nextptr>::*pnext(nextptr);

But that didn't work. Any idea?

+3  A: 

Queue<T, nextptr>::pnext is declared as type T* T::*, so it should look like this:

template<class T, T* T::*nextptr>
T* T::* Queue<T, nextptr>::pnext(nextptr);
sth
+4  A: 

Do you really need a static member variable of a template that has the same value as a template parameter?

The only use would be if its value were to change over the lifetime of the program but I really can't think of any situation were this would produce more benefit than cause confusion.

Charles Bailey
Thanks for the insight, I really didn't need the static member variable, only the template parameter.
agazso
he could make use of it if he only knows the type. then he can do Type::pnext; (much like those type-defs) but then i would recommend him to make the pointer const. but even so, i would prefer a static inline function.
Johannes Schaub - litb