I've got two c++ templates. I want to have h and cpp files. It works with only one template but it doesn't work with two different templates. I receive this error from gcc:
../Temp1.cpp:16:17: error: definition of ‘Name::Temp1<T>::Temp1()’ is not in namespace enclosing ‘Name::Temp1<T>’ [-fpermissive]
../Temp1.cpp:22:18: error: definition of ‘Name::Temp1<T>::~Temp1()’ is not in namespace enclosing ‘Name::Temp1<T>’ [-fpermissive]
make: *** [Temp2.o] Error 1
Here the code for Temp1 header:
#ifndef TEMP1_H_
#define TEMP1_H_
namespace Name {
template<class T>
class Temp1 {
public:
Temp1();
virtual ~Temp1();
};
#include "Temp1.cpp"
} /* namespace Name */
#endif /* TEMP1_H_ */
Temp1 cpp:
#ifndef TEMP1_CPP_
#define TEMP1_CPP_
#include "Temp1.h"
namespace Name {
template<class T>
Temp1<T>::Temp1() {
// TODO Auto-generated constructor stub
}
template<class T>
Temp1<T>::~Temp1() {
// TODO Auto-generated destructor stub
}
} /* namespace Name */
#endif
Temp2 header:
#ifndef TEMP2_H_
#define TEMP2_H_
#include "Temp1.h"
namespace Name {
template<class T>
class Temp2: public Temp1<T> {
public:
Temp2();
virtual ~Temp2();
};
#include "Temp2.cpp"
} /* namespace Name */
#endif /* TEMP2_H_ */
Temp2 cpp:
#ifndef TEMP2_CPP_
#define TEMP2_CPP_
#include "Temp2.h"
namespace Name {
template<class T>
Temp2<T>::Temp2() {
// TODO Auto-generated constructor stub
}
template<class T>
Temp2<T>::~Temp2() {
// TODO Auto-generated destructor stub
}
} /* namespace Name */
#endif