This header file has the enhancements posed in the first five floatVector problems. SeeExample: floatVector - Version 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
// fv3/floatVector.h - illustrates typical vector features
// Fred Swartz - 2004-12-01
#include <iostream>
using namespace std;
#ifndef floatVector_H
#define floatVector_H
class floatVector {
friend ostream& operator<<(ostream& os, const floatVector& fv);
public:
//... Constructors
floatVector(); // default constructor
floatVector(const floatVector& fv); // Copy constructor.
//... Destructor
~floatVector(); // Destructor.
//... Functions
float& at(int position) const; // Return reference to element at position.
float& back() const; // Return reference to last elem.
int capacity() const; // Return max size before reallocation.
void clear(); // Delete all items.
bool empty() const; // True if no elements, size()==0.
float& front() const; // Return reference to first element.
void pop_back(); // Remove last element.
void push_back(float item); // Add item to end.
void reserve(int cap); // Insure capacity at least cap.
int size() const; // Return number of elements in vector.
//... Operators
floatVector& operator=(const floatVector& fv);
float& operator[](int position) const;
bool operator==(const floatVector& v2) const;
private:
int _capacity; // current maximum size (number of floats).
int _size; // current "size"
float* _data; // pointer to array of floats
};
#endif
|