473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Calling a function in another class


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.

Thanks for any help

ostream& operator<< (ostream& out, const Entry& e)

{

Race* r;

out << "Yacht : " << *(e.what) << endl

<< "Race : " << r->Show () << endl

<< "Finish Place : " << e.place << endl

<< "Finish Time : " << e.time << endl << endl;
return out;

}

//Show () function within a Race class

void Race::Show (ostream& out) const

{

out << "Race Number : " << number << endl

<< "Race Date : " << date << endl << endl;

}


Jul 22 '05 #1
2 3350

"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
Jul 22 '05 #2
John J posted:

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.

Thanks for any help

ostream& operator<< (ostream& out, const Entry& e)

{

Race* r;

out << "Yacht : " << *(e.what) << endl

<< "Race : " << r->Show () << endl

<< "Finish Place : " << e.place << endl

<< "Finish Time : " << e.time << endl << endl;
return out;

}

//Show () function within a Race class

void Race::Show (ostream& out) const

{

out << "Race Number : " << number << endl

<< "Race Date : " << date << endl << endl;

}

"Race : " << Race::Show () << endl
The "Show" function must be declared static in the class declaration.
-JKop
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage...
10
by: Shayne Wissler | last post by:
I've overloaded the global new operator, so that I can, detect when I've run out of memory: extern void* operator new(size_t s) { void *r = malloc(s); if (!r && s) { fprintf(stderr, "Error: No...
3
by: Ken | last post by:
hello, I would to know if it is possible to call an object in a function within a class. Meaning , In a class, A function X calling onto a function Y, and function Y we want one of the two...
2
by: William Payne | last post by:
Hello, consider these following two classes. A base class, class MDIChildWindow, and a class inherting from that base class, class Document. In the static base member function callback() I obtain a...
8
by: Andreas Lagemann | last post by:
Hi, after browsing FAQ and archive for a while I decided that the following is a legal question. Consider this: Class Base { public: Base() {}
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
4
by: Bugs | last post by:
Hi, I wonder if anyone can help me out. I'm building a vb.net application that has a form with a panel that contains several other sub forms (as a collection of controls). What I'm wanting to...
3
by: drummond.ian | last post by:
Hello Everyone, This problem's been causing me a lot of trouble and I'm hoping somebody can help me out!! I have a dialog-based MFC application in visual studio 2003. I want to call a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.