0

Please find the code below:

#include <iostream> using namespace std; template<typename T> class A { static A* self; }; template<typename T> A* A<T>::self = NULL; int main() { return 0; } 

I am facing a compilation problem while initialising the static pointer. Even though so many links has said the same way (the way i initialised) but still the problem resist. Below is the compilation error.

"expected constructor, destructor, or type conversion before '*' token" 

2 Answers 2

2

A is a class template, so you need to specify the template parameter when defining the pointer to it.

Instead of:

template<typename T> A* A<T>::self = NULL; 

it should be:

template<typename T> A<T>* A<T>::self = NULL; 

Within the class body, specifying the template parameter is optional, so you can write A* there and it will be treated the same as A<T> *.

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

Comments

0

try:

template<typename T> A<T>* A<T>::self = NULL;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.