CPP/Templates/ClassTemplateExplicitInstantiation
From ProgrammingExamples
ClassTemplateExplicitInstantiation.cpp
#include <iostream> #include "Point.h" int main(int argc, char* argv[]) { Point<double> A; std::cout << A.Add( ) << std::endl; return 0; }
Point.h
#ifndef POINT_H #define POINT_H template <typename T> class Point { T x,y,z; public: double Add(); }; #endif
Point.cpp
#include "Point.h" template <typename T> double Point<T>::Add() { return 2.0 + 4.3; }; // You are required to instantiate all classes you might use from this template // since the function is not defined in the header. template class Point<double>; template class Point<float>;
CMakeLists.txt
Project(ClassTemplateExplicitInstantiation) ADD_EXECUTABLE(ClassTemplateExplicitInstantiation ClassTemplateExplicitInstantiation.cpp Point.cpp)