/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include "foo.hpp"
using namespace std;
int main()
{
cout<<"Hello World\n";
Foo foo;
foo.myMethod(1);
foo.myMethod(2.0);
// undefined reference to `void Foo::myMethod(float)'
// intFoo.myMethod(2.0F); <-- doesn't work as we don't have definition
return 0;
}
#include <typeinfo>
#include <iostream>
#include "foo.hpp"
template void Foo::myMethod(int var);
template void Foo::myMethod(double var);
template <typename T>
void Foo::myMethod(T var)
{
std::cout << typeid(T).name() << " - " << var << std::endl;
}
struct Foo
{
template<typename T>
void myMethod(T var);
};