Friend Classes

I can't figure out what I'm doing wrong. It says I put too few arguments but I did the same thing for the add, subtract, multiply, and divide functions and they worked. Thank you for your help!
 
Last edited on
It seems like you want the average function to average the two values in your math class, but it doesn't know what object to use.
You should change the function to this:
1
2
3
4
float average(math & mathObject)
{
    return (mathObject.n1 + mathObject.n2)/2.f;
}

declare it a friend like this:
 
friend float average(math &);

then when you call it, you should call it like this:
 
cout << "Average of " << maths.add() << " is " << average(maths);
Thank you. But what does the & do and is it possible to do it without the & ?

Actually figured it out thank you! What you pointed out really helped!
Last edited on
Topic archived. No new replies allowed.