Return to Index
Vector
This is a templated vector class. Unlike the Stack, *Hash, List,
and Queue classes, the Vector stores objects directly, not pointers
to them. That is, the declaration
   Vector int my_vec;
creates a vector of integers, and can be used just like an normal
C-style array with the [] operators. Note that if a vector
of objects is declared, for example
   Vector SomeClass my_obj_vec;
then the SomeClass class should make sure to properly override
the '=' operator, and it must also have a default constructor.
The vector class performs bounds checking, and aborts the application
if an index is out of bounds.
Method Summary: |
| Vector::Vector | (); |
| Vector::Vector | (int size); |
| Vector::Vector | (int size, const type& fill); |
| Vector::Vector | (const Vector& vec); |
const Vector& | Vector::operator= | (const Vector& vec); |
type& | Vector::operator[] | (int i); |
const type& | Vector::operator[] | (int i); |
type& | Vector::at | (int i); |
const type& | Vector::at | (int i); |
bool | Vector::resize | (int new_size, bool (=true) copy); |
int | Vector::length | (); |
int | Vector::size | (); |
type* | Vector::data | (); |
Vector::Vector |
Vector::Vector();
Constructs a new empty vector. |
Vector::Vector |
Vector::Vector(int size);
Constructs a new vector of the specified size. |
Parameters: |
int | size | The initial size of the vector; |
|
Vector::Vector |
Vector::Vector(int size, const type& fill);
Constructs a new vector of the specified size and fills with a default element. |
Parameters: |
int | size | The size of the vector. |
const type& | fill | The item to fill the vector with. |
|
Vector::Vector |
Vector::Vector(const Vector& vec);
Constructs a copy of an existing vector. |
Parameters: |
const Vector& | vec | The vector to copy. |
|
const Vector& Vector::operator= |
const Vector& Vector::operator=(const Vector& vec);
Assigns one vector to another. |
Parameters: |
const Vector& | vec | The vector to assign. |
|
type& Vector::operator[] |
type& Vector::operator[](int i);
Indexing operator to allow for assignment into the vector.    my_vec[2] = 2.4; |
Parameters: |
int | i | Specifies which item to return a reference to. |
|
const type& Vector::operator[] |
const type& Vector::operator[](int i);
Indexing operator to return elements in the vector.    double val = my_vec[2]; |
Parameters: |
int | i | Specifies which element to return. |
|
type& Vector::at |
type& Vector::at(int i);
Indexing operator to allow for assignment into the vector. Equivalent to the [] operator. |
Parameters: |
int | i | Specifies which index to return a reference to. |
|
const type& Vector::at |
const type& Vector::at(int i);
Indexing operator to return elements in the vector. Equivalent to the [] operator. |
Parameters: |
int | i | Specifies which element to return. |
|
bool Vector::resize |
bool Vector::resize(int new_size, bool (=true) copy);
Resizes the vector and copies the old elements over.
Returns: Returns whether the resize succeeded. |
Parameters: |
int | new_size | The new size of the vector. If this is shorter than the current size, the vector is truncated which may result in data loss. |
bool (=true) | copy | Whether the copy the old elements. Defaults to true. |
|
int Vector::length |
int Vector::length();
Returns the length of the array. |
int Vector::size |
int Vector::size();
Returns the length of the array. |
type* Vector::data |
type* Vector::data();
Returns a pointer to the internal C-style array. Use of this function is strongly discouraged. |
Generated automatically by docgen 0.0.1
© 2003 Aron Dobos