Original Post
Hi, i am trying to compile this but i cant, and i dont see the mistake, i get linker error of function func in VS2010, and in code blocks i get "undefined reference". Only works if i put the definition inline in the class, or in the header, but anything i put in cpp file i get the same errors.
File: A.h
#ifndef _A_H_
#define _A_H_
template <class T> class A
{
public:
int n;
A() {};
~A() {};
T func(T n);
};
#endif
File: A.cpp
#include "A.h"
template <class T> T A<T>::func(T n)
{
this->n = n;
return this->n;
}
File: main.cpp
#include <iostream>
#include "A.h"
int main()
{
A<int> a;
std::cout << a.func(2);
return 0;
}