Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "vektor.h"
- unsigned int Vektor::defSize = 7;
- double Vektor::defValue = -469.0;
- Vektor::Vektor(const Vektor& other) {
- this->nElements=other.nElements;
- this->pVec = new double[other.nElements];
- for (unsigned int i = 0;i < this->nElements;i++) this->pVec[i]=other.pVec[i];
- }
- Vektor::~Vektor() { delete[] this->pVec; }
- Vektor& Vektor::operator=(const Vektor& other) {
- if (this->pVec == other.pVec) return *this;
- delete pVec;
- this->pVec = new double[other.nElements];
- this->nElements=other.nElements;
- for (unsigned int i = 0;i < this->nElements;i++) this->pVec[i]=other.pVec[i];
- return *this;
- }
- double& Vektor::operator[](unsigned int idx) {
- if (idx < 0 || idx >= this->nElements) throw "WY9Z2V";
- return this->pVec[idx];
- }
- const double& Vektor::operator[](unsigned int idx) const {
- if (idx < 0 || idx > this->nElements) throw "WY9Z2V";
- return this->pVec[idx];
- }
- Vektor operator*(double val, const Vektor& vec) {
- Vektor result(vec.nElements);
- for (unsigned int i = 0; i < vec.nElements; i++) result.pVec[i]=vec.pVec[i]*val;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement