Difference between revisions of "CPP/Templates/PartialClassSpecialization"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) m (→Point.h) |
(→Point.h) |
||
Line 30: | Line 30: | ||
}; | }; | ||
− | template<typename T | + | template<typename T> |
class Point<T, int> | class Point<T, int> | ||
{ | { | ||
Line 50: | Line 50: | ||
////////////////// | ////////////////// | ||
− | template<class T | + | template<class T> |
void Point<T, int>::function1() | void Point<T, int>::function1() | ||
{ | { |
Revision as of 10:08, 6 April 2011
PartialClassSpecialization.cpp
#include <iostream> #include "Point.h" int main() { Point<int, int, double> a; Point<int, int*, 5> b; a.function1(); b.function1(); }
Point.h
#ifndef POINT_H #define POINT_H #include <iostream> #include <vector> template<typename T, typename U> class Point { void function1(); void function2(); }; template<typename T> class Point<T, int> { void function1(); }; #include "Point.txx" template<typename T, typename U> void Point<T,U>::function1() { std::cout << "Primary template function1" << std::endl; } template<typename T, typename U> void Point<T,U>::function2() { std::cout << "Primary template function2" << std::endl; } ////////////////// template<class T> void Point<T, int>::function1() { std::cout << "Partial specialization function1" << std::endl; } #endif
Point.txx
CMakeLists.txt
Project(PartialClassSpecialization) ADD_EXECUTABLE(PartialClassSpecialization PartialClassSpecialization.cpp)