You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2005 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
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
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'
Last edited by akmeref : August 4th, 2009 at 05:04 PM.