fork download
  1. using namespace std;
  2. //============================================================================================!
  3. #define PREDEFINE(anytype) template<typename anytype>
  4. #define SPECIALISEDTEMPLATE(Class,SpecialType) template<> class Class<SpecialType>
  5. //============================================================================================!
  6. PREDEFINE(Precision)
  7. class MyClass
  8. {
  9. public :
  10. MyClass();
  11. void Foo(Precision A);
  12. PREDEFINE(Precision2) void Foo(Precision2 B);
  13.  
  14. private :
  15. Precision mA;
  16. };
  17. //=======================================================================================!
  18. template<typename Precision>
  19. MyClass<Precision>::MyClass()
  20. :mA((Precision) -1)
  21. {
  22.  
  23. }
  24. //=======================================================================================!
  25. template<typename Precision>
  26. void MyClass<Precision>::Foo(Precision A)
  27. {
  28. //Do something here
  29. mA = A;
  30. }
  31. //=======================================================================================!
  32. template<typename Precision>
  33. PREDEFINE(Precision2)void MyClass<Precision>::Foo(Precision2 B )
  34. {
  35. mA = (Precision)B;
  36. }
  37. //=======================================================================================!
  38. // Template Specialization
  39. //=======================================================================================!
  40. SPECIALISEDTEMPLATE(MyClass,bool)
  41. {
  42. public :
  43. void Foo()
  44. {
  45. mA = true;
  46. }
  47. MyClass():mA(false){}
  48. private :
  49. bool mA;
  50. };
  51. //========================================================================================!
  52. int main()
  53. {
  54. MyClass<int> obj;
  55. obj.Foo(25.f);
  56. obj.Foo(25);
  57. obj.Foo(25.000000011);
  58. MyClass<bool> SpecialedObj;
  59. SpecialedObj.Foo();
  60. return 0;
  61. }
Success #stdin #stdout 0.02s 2720KB
stdin
Standard input is empty
stdout
Standard output is empty