Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "vektor.h"
- unsigned int Vektor::defSize = 12;
- double Vektor::defValue = 418;
- /// Másoló konstruktor.
- /// @param v - Vektor referencia
- Vektor::Vektor(const Vektor& v) {
- this->nElements = v.nElements;
- this->pVec = new double[this->nElements];
- for (unsigned int i = 0; i < this->nElements; i++) {
- this->pVec[i] = v.pVec[i];
- }
- }
- /// Destruktor.
- Vektor::~Vektor() {
- delete[] this->pVec;
- }
- /// Értékadó operátor.
- /// @param v - Vektor referencia
- /// @return - referencia az adott elemre
- Vektor& Vektor::operator=(const Vektor& v) {
- if (this != &v) {
- delete[] this->pVec;
- this->nElements = v.nElements;
- this->pVec = new double[this->nElements];
- for (unsigned int i = 0; i < this->nElements; i++) {
- this->pVec[i] = v.pVec[i];
- }
- }
- return *this;
- }
- /// Indexoperátorok.
- /// Túlcímzés esetén Ön nagybetűs Neptun-kódját tartalmazó const char* típusú kivételt dob!
- /// @param idx - index értéke
- /// @return - referencia az adott elemre
- double& Vektor::operator[](unsigned int idx) {
- if (idx >= this->nElements) {
- throw "ILE2S9";
- }
- return this->pVec[idx];
- }
- const double& Vektor::operator[](unsigned int idx) const {
- if (idx >= this->nElements) {
- throw "ILE2S9";
- }
- return this->pVec[idx];
- }
- /// Szorzás: Valós * Vektor
- /// @param val - valós érték (bal oldali operandus)
- /// @param vec - vektor, aminek minden elemét megszorosszuk (jobb oldali operandus)
- Vektor operator*(double val, const Vektor& vec) {
- Vektor vec_new = vec;
- for (unsigned int i = 0; i < vec.size(); i++) {
- vec_new[i] *= val;
- }
- return vec_new;
- }
Advertisement
Add Comment
Please, Sign In to add comment