4

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the insight, I really didn't need the static member variable, only the template parameter.
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.
3

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.