0

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;
}
2
Contributors
2
Replies
5
Views
4 Years
Discussion Span
Last Post by sabrimev
1

The error you are getting is saying that it can’t find an operator << that will take a vector. The vector class does not have built in stream operators so if you want to pass a vector to << than you need to write your own function to do that.

Votes + Comments
You are saying I should oveload << operator?
0

I found it It must be

for(unsigned int i=0;i <10;++i)
    cout << a.GetVect()[i] ; 

Thats all :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.