I get a compiling error in the main fuction 'cout << a.GetVect() ; '
I am not sure whether the problem is in the overloading function or in class.
Anyone has any idea why I take this error?
you can check the compiled code and errors in http://ideone.com/ODOJik
Thanks in advance..
#include <cstdlib>
#include <iostream>
#include <vector>
#include "OverLoad.h"
#include <cmath>
using namespace std;
class Overload {
public:
Overload();
Overload(int);
Overload operator+(Overload &) ;
void SetK(int k);
int GetK() const;
void SetVect(vector<double> vect);
vector<double> GetVect() const;
private:
vector<double> vect ;
int k ;
};
int main(int argc, char** argv) {
Overload a,b(10),c(10) ;
a = b+c ;
cout << a.GetVect() ;
return 0;
}
Overload::Overload() {
k=10 ;
for(unsigned int i=0;i<k ; ++i){
double res = 1/pow(i,2) ;
vect.push_back(res);
}
}
Overload::Overload(int k) {
for(unsigned int i=0;i<k ; ++i){
double res = 1/pow(i,2) ;
vect.push_back(res);
}
}
Overload Overload::operator+(Overload &a){
Overload x ;
for(unsigned int i=0 ;i<vect.size();i++) {
double res = vect[i] + a.vect[i];
x.vect.push_back(res) ;
}
return x ;
}
void Overload::SetK(int k) {
this->k = k;
}
int Overload::GetK() const {
return k;
}
void Overload::SetVect(vector<double> vect) {
this->vect = vect;
}
vector<double> Overload::GetVect() const {
return vect;
}