# C++: OOP: Classes: Example: floatVector

## Fixed array sizes and Vectors

The fixed size of arrays is often a problem and frequently the source of bugs. The STL (Standard Template Library) `vector` class is a dynamically expandable array. The `floatVector` example here shows how `vector` is implemented, but without the extra distraction of templates and iterators that are in the STL `vector` class. The code is divided into three files, one for testing, one containing the header file, and one which has the implementation of some of the methods.

- floatVectorTest.cpp - test program
- floatVector.h - header
- floatVector.cpp - implementation

## Enhancements

Many improvements can be made to this class.

1. Write the functions that are declared in the header (`floatVector.h`), but not defined in `floatVector.cpp`. These are `back`, `clear`, `empty`, `front`, and `pop_back`, which should all do the same thing as the standard `vector` functions. Modify the test program to test all functions.
2. The `at` function in the `vector` class throws the `out_of_range` exception if the subscript is out of range. Change `at` to do that, but also do the same for subscription and throw an exception in the constructor if the size isn't greater than zero. See Exceptions.
3. Because this class dynamically allocates memory, it's necessary to define assignment (operator=), a copy constructor, and a destructor. See Overloading assignment, Copy constructor, and Destructors.
4. Define the output operator << by overloading operator<< as a friend function. You will have to decide what vector output should look like. One suggestion is that it should produce a comma-separated list enclosed in braces, like the notation for array initialization. See Overloading << and >>.
5. Make this into a general template class that will work with any type. Call it `myVector` to distinguish it from the standard `vector` class.