Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Datatype.h
- //
- // A test data type for use when designing template classes.
- //
- #ifndef __DATATYPE_H__
- #define __DATATYPE_H__
- //
- // Datatype
- //
- // A sample data type to be used when designing template
- // classes. A Datatype only implements a few functions,
- // making it easier to determine which functions a template
- // function or class really uses. A Datatype also has a
- // value, named n, that allows it to be distinguished from
- // other Datatypes. A Datatype implements the following
- // functions:
- // <1> Constructor requiring an int
- // <2> Copy Constructor
- // <3> Destructor
- // <4> Equality Test Operator
- //
- // If these, the constructor requiring an int is intended to
- // not be used by the template function or class. It is
- // intended to be used by the testing to to create instances
- // of Datatype to test the class on.
- //
- class Datatype
- {
- public:
- //
- // Constructor
- //
- // Purpose: To create a new Datatype with the specified value.
- // This function is intended to be invoked by the code
- // testing the template, not by the template code
- // itself.
- // Argument(s):
- // <1> N: The value for the new Datatype
- // Precondition(s): N/A
- // Returns: N/A
- // Side Effect: A new Datatype is created with a value of N.
- //
- Datatype (int N) : n(N)
- {}
- //
- // Copy Constructor
- //
- // Purpose: To create a new Datatype as a copy of another.
- // Argument(s):
- // <1> original: The Datatype to copy
- // Precondition(s): N/A
- // Returns: N/A
- // Side Effect: A new Datatype is created with the same value
- // as original.
- //
- Datatype (const Datatype& original) : n(original.n)
- {}
- //
- // Destructor
- //
- // Purpose: To safely destroy this Datatype without memory
- // leaks. This function does nothing, but is provided
- // so that there is a destructor in this class to be
- // invoked.
- // Argument(s): N/A
- // Precondition(s): N/A
- // Returns: N/A
- // Side Effect: None. But some other class might have one.
- //
- ~Datatype ()
- {}
- //
- // Equality Test Operator
- //
- // Purpose: To determine if two Datatypes are equal. Two
- // Datatypes are considered to be equal if they have
- // the same identifying value.
- // Argument(s):
- // <1> other: The other Datatype
- // Precondition(s): N/A
- // Returns: Whether this Datatype and other are equal.
- // Side Effect: N/A
- //
- bool operator== (const Datatype& other) const
- { return (n == other.n); }
- private:
- //
- // Default Constructor
- // Assignment Operator
- // Stream Insertion Operator
- //
- // These functions have been deliberately not implemented.
- //
- Datatype ();
- Datatype& operator= (const Datatype& original);
- public:
- int n;
- };
- //
- // Stream Insertion Operator
- //
- // This functions has been deliberately not implemented.
- //
- // The prototype has not been provided because that would
- // require the <iostream> library to be #included in this
- // header file. This would #include the <iostream> library
- // in the template being tested, which could change the
- // testing results. For example, if the template file
- // required the <iostream> library but did not #include it,
- // #including it in this file would cause thae test to
- // succeed when it should have failed.
- //
- // std::ostream& operator<< (std::ostream& r_out,
- // const Datatype& datattype);
- //
- #endif
Add Comment
Please, Sign In to add comment