Advertisement
lukibeni

vektorszopás

Mar 13th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include "vektor.h"
  2.  
  3. unsigned int Vektor::defSize = 7;
  4. double Vektor::defValue = -469.0;
  5.  
  6. Vektor::Vektor(const Vektor& other) {
  7. this->nElements=other.nElements;
  8. this->pVec = new double[other.nElements];
  9. for (unsigned int i = 0;i < this->nElements;i++) this->pVec[i]=other.pVec[i];
  10. }
  11.  
  12. Vektor::~Vektor() { delete[] this->pVec; }
  13.  
  14. Vektor& Vektor::operator=(const Vektor& other) {
  15. if (this->pVec == other.pVec) return *this;
  16. delete pVec;
  17. this->pVec = new double[other.nElements];
  18. this->nElements=other.nElements;
  19. for (unsigned int i = 0;i < this->nElements;i++) this->pVec[i]=other.pVec[i];
  20. return *this;
  21. }
  22.  
  23. double& Vektor::operator[](unsigned int idx) {
  24. if (idx < 0 || idx >= this->nElements) throw "WY9Z2V";
  25. return this->pVec[idx];
  26. }
  27.  
  28.  
  29. const double& Vektor::operator[](unsigned int idx) const {
  30. if (idx < 0 || idx > this->nElements) throw "WY9Z2V";
  31. return this->pVec[idx];
  32. }
  33.  
  34. Vektor operator*(double val, const Vektor& vec) {
  35. Vektor result(vec.nElements);
  36. for (unsigned int i = 0; i < vec.nElements; i++) result.pVec[i]=vec.pVec[i]*val;
  37. return result;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement