operators

Hi,
The error I am gettling is: no match for 'operator<<' in 'n2<<std::endl'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//...
int main()
{
    Average n1(5);      //holds a number
    Average n2(20);     //holds a number

    //print average
    cout<<"Average:\n\n"<<n1&n2<<endl;

    //terminate program
    return 0;
}

//...

double Average::operator&(Average a)    //returns the average of 2 objects
{
    return (n + a.n)/2;
}


Thanks for your help.
Last edited on
closed account (zb0S216C)
std::ostream::operator << () doesn't know how to handle your Average class. You need to overload operator << () to support your class. For instance:

1
2
3
4
5
std::ostream &operator << (std::ostream OutStream, Average const &AverageNo)
{
    OutStream << AverageNo.n;
    return(OutStream);
}

You could overload the operator natively, too.

Warning! Untested code.

Wazzak
Last edited on
Topic archived. No new replies allowed.