< previous page page_1021 next page >

Page 1021
        //     ELSE
        //          Program has halted with error message

    void CopyFrom( /* in */ DynArray array2 );
        // Postcondition:
        //     IF there is enough memory for a deep copy of array2
        //         This object is a copy of array2 (deep copy)
        //     ELSE
        //         Program has halted with error message

    DynArray( /* in */ int arrSize );
        // Constructor
        // Precondition:
        //     arrSize is assigned
        // Postcondition:
        //     IF arrSize >= 1  &&  There is enough memory
        //         Array of size arrSize is created with all
        //         array elements == 0
        //     ELSE
        //         Program has halted with error message

    DynArray( const DynArray&array2 );
        // Copy-constructor
        // Postcondition:
        //     IF there is enough memory
        //         New array is created with size and contents
        //         the same as array2 (deep copy)
        //     ELSE
        //         Program has halted with error message
        // Note:
        //     This constructor is implicitly invoked whenever a
        //     DynArray object is passed by value, is returned as
        //     a function value, or is initialized by another
        //     DynArray object in a declaration

    ~DynArray();
        // Destructor
        // Postcondition:
        //     Array is destroyed
private:
    int* arr;
    int  size;
};
Below is a simple client program that creates two class objects, x and y, stores the values 100, 101, 102, into x, copies object x to object y, and prints out the contents of y.

 
< previous page page_1021 next page >