Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 15th, 2010 | Syntax: C++ | Size: 0.79 KB | Hits: 41 | Expires: Never
Copy text to clipboard
  1. #include "vektor.h"
  2. #include <iostream>
  3.  
  4.  
  5. int Vektor::defMeret=3;
  6. double Vektor::defErtek=-26;
  7.  
  8. Vektor::~Vektor (){if(pVec!=NULL) delete []pVec;};
  9.  
  10. Vektor::Vektor(const Vektor& vt) {
  11.   nElem=vt.nElem;
  12.   if(pVec!=NULL) delete[] pVec;
  13.   pVec=new double[nElem];
  14.   for(int i=0;i<nElem;i++) pVec[i]=vt.pVec[i];};
  15.  
  16. double& Vektor::operator[](int idx){
  17.  if (idx<0) throw "Az index nem lehet kisebb mint 0.";
  18.  if (idx>=nElem) throw "Tulindexeles.";
  19.  return pVec[idx];};
  20.  
  21. Vektor& Vektor::operator=(const Vektor& vt){
  22.  nElem=vt.nElem;
  23.  pVec=new double[nElem];
  24.  for(int i=0;i<nElem;i++) pVec[i]=vt.pVec[i];
  25.  return *this;};
  26.  
  27. Vektor operator*(double a, Vektor& vt){
  28.  Vektor tmp;
  29.  tmp.pVec=new double[tmp.nElem=vt.nElem];
  30.  for(int i=0;i<tmp.nElem;i++) tmp.pVec[i]=a*vt.pVec[i];
  31.  return tmp;};