MyVector
MyVector Class Reference

My own vector class. More...

#include <myvector.h>

Public Member Functions

 MyVector (const long long int n=0)
 Allocates a vector with n elements on the heap. More...
 
 MyVector (const MyVector &orig)
 Allocates a vector with the same elements as vector orig and copies its elements. More...
 
virtual ~MyVector ()
 Deallocates the heap memory. More...
 
MyVectoroperator= (MyVector const &orig)
 Reallocates the vector with the same elements as vector orig and copies its elements. More...
 
const long long int & size () const
 Returns the number of elements. More...
 
double & operator[] (const long long int i)
 Returns the value of element i. More...
 
const double & operator[] (const long long int i) const
 Returns the value of element i. More...
 

Protected Attributes

long long int length_
 number of elements More...
 
double * val_
 pointer to allocated memory More...
 

Friends

std::ostream & operator<< (std::ostream &s, MyVector const &orig)
 Output of the vector orig. More...
 

Detailed Description

My own vector class.

The macro DEBUG switches the range check on/off.

Definition at line 10 of file myvector.h.

Constructor & Destructor Documentation

◆ MyVector() [1/2]

MyVector::MyVector ( const long long int  n = 0)

Allocates a vector with n elements on the heap.

Parameters
[in]nvector length
Warning
Throws an exception in case of insufficient memory on the heap.

Definition at line 8 of file myvector.cpp.

◆ MyVector() [2/2]

MyVector::MyVector ( const MyVector orig)

Allocates a vector with the same elements as vector orig and copies its elements.

Parameters
[in]origoriginal vector
Warning
Throws an exception in case of insufficient memory.

Definition at line 28 of file myvector.cpp.

◆ ~MyVector()

MyVector::~MyVector ( )
virtual

Deallocates the heap memory.

Definition at line 38 of file myvector.cpp.

Member Function Documentation

◆ operator=()

MyVector & MyVector::operator= ( MyVector const &  orig)

Reallocates the vector with the same elements as vector orig and copies its elements.

Parameters
[in]origoriginal vector
Warning
Throws an exception in case of insufficient memory.

Definition at line 45 of file myvector.cpp.

◆ operator[]() [1/2]

double& MyVector::operator[] ( const long long int  i)
inline

Returns the value of element i.

Parameters
[in]iindex
Returns
value
Warning
Throws an exception "OutOfRange" in case an invalid index i.

Definition at line 64 of file myvector.h.

◆ operator[]() [2/2]

const double& MyVector::operator[] ( const long long int  i) const
inline

Returns the value of element i.

Parameters
[in]iindex
Returns
value
Warning
Throws an exception "OutOfRange" in case an invalid index i.

Definition at line 79 of file myvector.h.

◆ size()

const long long int& MyVector::size ( ) const
inline

Returns the number of elements.

Returns
Number of elements

Definition at line 53 of file myvector.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  s,
MyVector const &  orig 
)
friend

Output of the vector orig.

Parameters
[in]soutput stream
[in]origvector
Warning
Throws an exception in case of insufficient memory.

Member Data Documentation

◆ length_

long long int MyVector::length_
protected

number of elements

Definition at line 102 of file myvector.h.

◆ val_

double* MyVector::val_
protected

pointer to allocated memory

Definition at line 103 of file myvector.h.


The documentation for this class was generated from the following files: