Static initialization of a static pointer in C ++

I have a template class that has a static member pointer, like this:

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

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

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

But that did not work. Any idea?

+4
source share
2 answers

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

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

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

The only use would be if its meaning changed during the life of the program, but I really can’t think of any situation, it would be more useful than cause confusion.

+4
source

All Articles