I have a Non-integral Constant declaration in a class.
I keep getting the following:
ComponentClass.h:14: error: template declaration of
const typename ComponentClass<T> ::position NULLPOSITION
ComponentClass.h:14: error: position was not declared in this scope
ComponentClass.h:14: error: expected;before numeric constant
Please find below my code.
ComponentClass.h
#ifndef _ComponentClass_H
#define _ComponentClass_H
template< class T>
class ComponentClass
{
public:
typedef ComponentClass* position;
ComponentClass();
};
template<class T>
const typename ComponentClass<T>::position NULLPOSITION=(position)0;
template<class T>
ComponentClass<T>::ComponentClass(){}
#endif
The reason you’re seeing this error is that
positionis not in scope in the expression(position)0. You can omit the cast altogether (i.e,0). If you wanted to include it, you would need to usetypename ComponentClass<T>::positionas you did in the definition ofNULLPOSITION.You appear to be defining a static member variable without first declaring it in the class like so:
Then you can define it outside the class as you do now. In order to avoid redundant definitions, however, the typical solution is as follows:
That is, don’t make
NULLPOSITIONa member of every instantiation ofComponentClass, but instead let allComponentClassinstantiations share a single definition.