Difference between revisions of "CPP/Templates/FunctionTemplateHeaderOnly"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==FunctionTemplate.cpp== <source lang="cpp"> #include <iostream> template<typename T> void PrintSomething(T something); int main(int, char*[]) { double a = 1.2; PrintSometh…')
(No difference)

Revision as of 10:07, 24 January 2011

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)