I want to implement a template in a class file instead of implement all the code in the same file. But the problem is I have a linked error and I don't know what to do in order to solve it ? If you have any idea in order to help it will be graceful.
Main.cpp
#include <iostream>
#include <string>
#include "Myclass.h"
using namespace std;
int main()
{
Myclass<int> firstObject;
firstObject.setValue(2);
int nbr = firstObject.getValue();
system("PAUSE");
return 0;
}
Myclass.cpp
#include "Myclass.h"
template <class Temp>
Myclass<Temp>::Myclass()
{
}
template <class Temp>
void Myclass<Temp>::setValue(Temp a)
{
first = a;
}
template <class Temp>
Temp Myclass<Temp>::getValue()
{
return first;
}
Myclass.h
#pragma once
template <class Temp>
class Myclass
{
public:
Myclass();
void setValue(Temp a);
Temp getValue();
private:
Temp first;
};