C ++: for a specialized member, the syntax "template <>" is required
What am I doing wrong?
template<class T>
class Binder
{
public:
static std::vector< Binder< T >* > all;
Node<T>* from;
Node<T>* to;
Binder(Node<T>* fnode, Node<T>* tonode)
{
from = fnode;
to = tonode;
Binder<T>::all.push_back(this);
}
};
std::vector<Binder<int>*> Binder<int>::all = std::vector< Binder<int>* >(); //here it is
Thank.
The definition of a static member is interpreted by the compiler as a specialization (in fact, this is a specialization: you specify an declaration that refers to T = int). This can be fixed by adding template<>before defining.
Defining static members in templates is a bit of a mess: a static member must be defined outside the header, and this is only possible if you already know everything possible Tfor your binder.
, T=int. , Binder<double> -, undefined.