Thursday, 31 August 2017

c++ - How to use function with template, When it declare in .hpp file and implementation in .cpp file

I want to declare function, with template value, in header file. And implementation it in cpp file and call the function from main.
But i want to do it without using class.
How do i do it?




Thanks



temp.hpp :



#ifndef TEMP_HPP
#define TEMP_HPP
template
void show( T a);
#endif /* TEMP_HPP */



temp.cpp :



#include 
#include "temp.hpp"
template
void show( T a)
{
std::cout << "a:" << a << std::endl;
}



main :



#include 
#include "TextTable.h"
#include "temp.hpp"

int main()
{

int a = 5;
float b = 2.5;
show(a);
return 0;
}

No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...