I am trying understand the concept of static data member templates. And i came across the following example in a book:
class Collection {
public:
template<typename T>
static T zero = 0;
};
When i try to execute the program it gives the error that:
undefined reference to `Collection::zero<int>'
To solve the above error i tried added the following code in the above program but it still gives error:
template<typename T> T Collection::zero = 0; //even after adding this it still gives error
Error now says:
duplicate initialization of 'Collection::zero'
My question is that is this a mistake(typo) in this example of the book. If yes, then what is the problem and how can i solve it?