CPP/Templates/FunctionTemplateExplicitInstantiation

From ProgrammingExamples
< CPP
Revision as of 21:46, 29 January 2011 by Daviddoria (Talk | contribs)

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

FunctionTemplateExplicitInstantiation.cpp

#include <iostream>
 
#include "Point.h"
 
int main(int, char*[])
{
  PrintSomething(1.2);
 
  // Sometimes have to do this:
  PrintSomething<double>(1.2);
 
  return 0;
}

Point.h

template<typename T>
void PrintSomething(T something);

Point.cpp

#include "Point.h"
 
#include <iostream>
 
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(FunctionTemplateExplicitInstantiation)
 
ADD_EXECUTABLE(FunctionTemplateExplicitInstantiation FunctionTemplateExplicitInstantiation.cpp Point.cpp)