I am trying to make an example of using templates in order to learn how to use them. I have made a project in Visual Studio 2010 C++ with three files:
Controller.cpp:
#include <iostream>
#include "Foo.h"
using namespace std;
int main(){
Example<int,string> example;
example.appols(5, "Hi");
return 0;
}
Foo.h:
#include <iostream>
using namespace std;
template <class T, class E>
class Foo{
public:
void printThis(T t, E e);
};
template <class T, class E>
class Example{
public:
void appols(T t, E e);
};
Foo.ipp:
#include <iostream>
#include "Foo.h"
using namespace std;
template<class T, class E>
void Foo<T, E>::printThis(T t, E e){
cout << "FOO! " << t << ' ' << e << endl;
}
template<class T, class E>
void Example<T, E>::appols(T t, E e){
cout << "APPOLS!! " << t << ' ' << e << endl;
Foo<T,E> f;
f.printThis(t,e);
}
When I try to compile, I get:
1>------ Build started: Project: Template Practive, Configuration: Debug Win32 ------
1>Controller.obj : error LNK2019: unresolved external symbol "public: void __thiscall Example<int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::appols(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?appols@?$Example@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>C:\Users\Matthew\documents\visual studio 2010\Projects\Template Practive\Debug\Template Practive.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Could you help me see what I have done wrong here and where error LNK2019
is coming from?
Thank you in advance!