"John J" <...@...> wrote in message
news:af******************************@news.teranew s.com...
I have written the following overload of operator << as a display
function. In the code I unsuccessfully try and call a function within another
class(<< "Race : " << r->Show () << endl). The Show function is in a class called
Race which is also included below. I'd greatly appreciate some guidance on
what I'm doing wrong.
What you are doing wrong it not thinking clearly about *which* Race object
you are trying to use to call the Show function. Which Race is it that you
want to Show?
Thanks for any help
ostream& operator<< (ostream& out, const Entry& e)
{
Race* r;
This is a pointer to a race object. But is has not been initialised to point
anywhere.
out << "Yacht : " << *(e.what) << endl
<< "Race : " << r->Show () << endl
Now you are using an uninitialised pointer. I would expect a program crash
at this point.
<< "Finish Place : " << e.place << endl
<< "Finish Time : " << e.time << endl << endl;
return out;
}
//Show () function within a Race class
Hard to know how to fix it because I don't know what you are trying to
achieve.
Presumably each Yacht is associated with a Race in some way (each Yacht is
entered in a Race maybe). Somehow you have to get that Race object that is
associated with the Yacht object that you are trying to display and use that
in your operator<< function. One way would be if each Yacht object had a
Race object as a member variable but it all depends on exactly what you are
trying to do.
The way you've written it, it looks like you are trying to conjure a Race
object out of thin air, that would be perfectly possible, but I doubt it is
what you want to do.
john