Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector {
- //a
- private:
- float size;
- long long startingIndex;
- double* data;
- //b
- Vector(float size, long long startingIndex) : size{size}, startingIndex{startingIndex}
- {
- if(size<1)
- data = nullptr;
- else
- data = new double(size);
- }
- //c
- ~Vector() {
- if (nullptr != data)
- {
- delete data;
- }
- }
- //d konstruktor kopiujacy
- Vector(const Vector& x){
- this->size = x.size;
- this->startingIndex = x.startingIndex;
- if (size > 0) {
- data = new double[size]();
- copy(x.data, x.data + x.size, this->data);
- }
- else
- data = nullptr;
- }
- //f para operatorow []
- double& operator[](const size_t index) {
- if (startingIndex + index > size - 2) {
- throw std::out_of_range("out of range");
- }
- return data[startingIndex + index];
- }
- const double& operator[](const size_t index) const {
- if (startingIndex + index > size - 2) {
- throw std::out_of_range("out of range");
- }
- return data[startingIndex + index];
- }
- //g operator ()
- float operator()() const {
- return size;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement