Guest User

Untitled

a guest
Apr 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.44 KB | None | 0 0
  1. //
  2. //  Datatype.h
  3. //
  4. //  A test data type for use when designing template classes.
  5. //
  6.  
  7. #ifndef __DATATYPE_H__
  8. #define __DATATYPE_H__
  9.  
  10.  
  11.  
  12. //
  13. //  Datatype
  14. //
  15. //  A sample data type to be used when designing template
  16. //    classes.  A Datatype only implements a few functions,
  17. //    making it easier to determine which functions a template
  18. //    function or class really uses.  A Datatype also has a
  19. //    value, named n, that allows it to be distinguished from
  20. //    other Datatypes.  A Datatype implements the following
  21. //    functions:
  22. //  <1> Constructor requiring an int
  23. //  <2> Copy Constructor
  24. //  <3> Destructor
  25. //  <4> Equality Test Operator
  26. //
  27. //  If these, the constructor requiring an int is intended to
  28. //    not be used by the template function or class.  It is
  29. //    intended to be used by the testing to to create instances
  30. //    of Datatype to test the class on.
  31. //
  32. class Datatype
  33. {
  34.   public:
  35. //
  36. //  Constructor
  37. //
  38. //  Purpose: To create a new Datatype with the specified value.
  39. //           This function is intended to be invoked by the code
  40. //           testing the template, not by the template code
  41. //           itself.
  42. //  Argument(s):
  43. //  <1> N: The value for the new Datatype
  44. //  Precondition(s): N/A
  45. //  Returns: N/A
  46. //  Side Effect: A new Datatype is created with a value of N.
  47. //
  48.  
  49.     Datatype (int N) : n(N)
  50.     {}
  51.  
  52. //
  53. //  Copy Constructor
  54. //
  55. //  Purpose: To create a new Datatype as a copy of another.
  56. //  Argument(s):
  57. //  <1> original: The Datatype to copy
  58. //  Precondition(s): N/A
  59. //  Returns: N/A
  60. //  Side Effect: A new Datatype is created with the same value
  61. //       as original.
  62. //
  63.  
  64.     Datatype (const Datatype& original) : n(original.n)
  65.     {}
  66.  
  67. //
  68. //  Destructor
  69. //
  70. //  Purpose: To safely destroy this Datatype without memory
  71. //           leaks. This function does nothing, but is provided
  72. //           so that there is a destructor in this class to be
  73. //           invoked.
  74. //  Argument(s): N/A
  75. //  Precondition(s): N/A
  76. //  Returns: N/A
  77. //  Side Effect: None.  But some other class might have one.
  78. //
  79.  
  80.     ~Datatype ()
  81.     {}
  82.  
  83. //
  84. //  Equality Test Operator
  85. //
  86. //  Purpose: To determine if two Datatypes are equal.  Two
  87. //           Datatypes are considered to be equal if they have
  88. //           the same identifying value.
  89. //  Argument(s):
  90. //  <1> other: The other Datatype
  91. //  Precondition(s): N/A
  92. //  Returns: Whether this Datatype and other are equal.
  93. //  Side Effect: N/A
  94. //
  95.  
  96.     bool operator== (const Datatype& other) const
  97.     { return (n == other.n); }
  98.  
  99.   private:
  100. //
  101. //  Default Constructor
  102. //  Assignment Operator
  103. //  Stream Insertion Operator
  104. //
  105. //  These functions have been deliberately not implemented.
  106. //
  107.  
  108.     Datatype ();
  109.     Datatype& operator= (const Datatype& original);
  110.  
  111.   public:
  112.     int n;
  113. };
  114.  
  115. //
  116. //  Stream Insertion Operator
  117. //
  118. //  This functions has been deliberately not implemented.
  119. //
  120. //  The prototype has not been provided because that would
  121. //    require the <iostream> library to be #included in this
  122. //    header file.  This would #include the <iostream> library
  123. //    in the template being tested, which could change the
  124. //    testing results.  For example, if the template file
  125. //    required the <iostream> library but did not #include it,
  126. //    #including it in this file would cause thae test to
  127. //    succeed when it should have failed.
  128. //
  129. // std::ostream& operator<< (std::ostream& r_out,
  130. //                            const Datatype& datattype);
  131. //
  132.  
  133.  
  134.  
  135. #endif
Add Comment
Please, Sign In to add comment