1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #include<iostream>
template <typename T0,typename T1> class Entity { public: Entity(T0 a, T1 b) { std::cout << "Primary Template" << std::endl; std::cout << "<" << typeid(T0).name() << "," << typeid(T1).name() << ">: " << a << " " << b << std::endl << std::endl; }
};
template <> class Entity<float,float> { public: Entity(float a, float b) { std::cout << "Full Specialization" << std::endl; std::cout << "<float,float>: " << a << " " << b << std::endl << std::endl; } };
template<typename T> class Entity<T, int> { public: Entity(T a, int b) { std::cout << "Partial Specialization" << std::endl; std::cout << "<" << typeid(T).name() << "," << "int" << ">: " << a << " " << b << std::endl << std::endl; } };
int main() {
Entity<int,int>(1, 3); Entity<float,float>(1, 3); Entity<double,double>(1, 3); Entity<double, int>(1, 3); Entity<int, double>(1, 3); } Partial Specialization <int,int>: 1 3
Full Specialization <float,float>: 1 3
Primary Template <double,double>: 1 3
Partial Specialization <double,int>: 1 3
Primary Template <int,double>: 1 3
|