about summary refs log tree commit diff
path: root/cpptour/Vector.cc
blob: aa09eef090dd7d0ec7295066265bb4178fadccff (plain) (blame)
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
#include <stdexcept>

#include "Vector.h"

using namespace std;

Vector::Vector (int s)
{
  if (s < 0)
    throw length_error{"You're being negetive!"};
  elem = new double[s];
  sz = s;
}

double& Vector::operator[] (int i)
{
  if (i < 0 || size() <= i)
    throw out_of_range{"Vector::operator[]"};
  return elem[i];
}

int Vector::size () noexcept
{
  return sz;
}