Hi,
Is it not possible to have the method definitions of a template class in a separate src file, instead of defining everything in a single file in .NET?(Because you do not have an example doing this in the book)
If it is posible, why do i get an error C2995 for the following trivial code?
In file test.h
Code:
#ifndef TEST_H
#define TEST_H
template<typename T>
class test
{
public:
test();
~test();
void setV(T i);
private:
T value;
};
#include "test.cpp"
#endif
and in file test.cpp
Code:
#include"test.h"
template<typename T>
test<T>::test(){}
template<typename T>
test<T>::~test(){}
template<typename T>
void test<T>::setV(T i){value = i;}
Why do I get this? It is obvious that the methods are declared but not defined in the test.h
Thank you
d:\testCPP_akis\tempS\tempS\test.cpp(4) : error C2995: 'test<T>::test(void)' : template function has already been defined
d:\testCPP_akis\tempS\tempS\test.h(8) : see declaration of 'test<T>::test'
d:\testCPP_akis\tempS\tempS\test.cpp(7) : error C2995: 'test<T>::~test(void)' : template function has already been defined
d:\testCPP_akis\tempS\tempS\test.h(9) : see declaration of 'test<T>::~test'
d:\testCPP_akis\tempS\tempS\test.cpp(10) : error C2995: 'void test<T>::setV(T)' : template function has already been defined
d:\testCPP_akis\tempS\tempS\test.h(10) : see declaration of 'test<T>::setV'