I am trying to a create a class TemplateTest<T>
which accepts a single parameter - the class T
. I have the following code which declares the class TemplateTest
and the constructor:
//in TemplateTest.h
#ifndef TEMPLATETEST_H
#define TEMPLATETEST_H
template<class T>
class TemplateTest
{
T property;
public:
TemplateTest(T value);
};
#endif // TEMPLATETEST_H
//in TemplateTest.cpp
#include<iostream>
#include "TemplateTest.h"
using namespace std;
template<class T>
TemplateTest<T>::TemplateTest(T value)
: property(value) {};
I'm not sure where the error is, but when I call the constructor in main.cpp
with a parameter p
I get the message: undefined reference to TemplateTest<p>::TemplateTest(p)
.
//in main.cpp
#include<iostream>
#include "TemplateTest.h"
int main()
{
int g = 6;
TemplateTest<int> temp(g);
return 0;
}
//returns "undefined reference to TemplateTest<int>::TemplateTest(int)
What am I doing wrong?