Difference between revisions of "CPP/Templates/FunctionTemplateHeaderOnly"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (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…') |
Daviddoria (Talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == | + | ==FunctionTemplateHeaderOnly.cpp== |
<source lang="cpp"> | <source lang="cpp"> | ||
#include <iostream> | #include <iostream> | ||
− | + | #include "Point.h" | |
− | + | ||
int main(int, char*[]) | int main(int, char*[]) | ||
{ | { | ||
− | + | PrintSomething(1.0); | |
− | PrintSomething( | + | |
// Sometimes have to do this: | // Sometimes have to do this: | ||
− | PrintSomething<double>( | + | PrintSomething<double>(1.0); |
return 0; | return 0; | ||
} | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | ==Point.h== | ||
+ | <source lang="cpp"> | ||
template<typename T> | template<typename T> | ||
Line 22: | Line 25: | ||
std::cout << something << std::endl; | std::cout << something << std::endl; | ||
} | } | ||
− | |||
− | |||
</source> | </source> | ||
Line 31: | Line 32: | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
− | Project( | + | Project(FunctionTemplateHeaderOnly) |
− | ADD_EXECUTABLE( | + | ADD_EXECUTABLE(FunctionTemplateHeaderOnly FunctionTemplateHeaderOnly.cpp) |
</source> | </source> |
Latest revision as of 22:43, 29 January 2011
FunctionTemplateHeaderOnly.cpp
#include <iostream> #include "Point.h" int main(int, char*[]) { PrintSomething(1.0); // Sometimes have to do this: PrintSomething<double>(1.0); return 0; }
Point.h
template<typename T> void PrintSomething(T something) { std::cout << something << std::endl; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(FunctionTemplateHeaderOnly) ADD_EXECUTABLE(FunctionTemplateHeaderOnly FunctionTemplateHeaderOnly.cpp)