CPP/Templates/FunctionTemplateHeaderOnly

From ProgrammingExamples
< CPP
Revision as of 10:07, 24 January 2011 by Daviddoria (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

FunctionTemplate.cpp

#include <iostream>
 
template<typename T>
void PrintSomething(T something);
 
int main(int, char*[])
{
  double a = 1.2;
  PrintSomething(a);
 
  // Sometimes have to do this:
  PrintSomething<double>(a);
 
  return 0;
}
 
template<typename T>
void PrintSomething(T something)
{
  std::cout << something << std::endl;
}
 
template void PrintSomething<double>(double);

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(FunctionTemplate)
 
ADD_EXECUTABLE(FunctionTemplate FunctionTemplate.cpp)