473,659 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3366

"John J" <...@...> wrote in message
news:af******** *************** *******@news.te ranews.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
2422
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 collection is not used in this class. (singleton class + override InitializeLifetimeService ) The service class uses C++ unmanaged function from dll (using DLLimport).
10
1891
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 more memory."); exit(1); } return r;
3
2386
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 calculation ( eg seconds , out of seconds and minutes) thanks , Ken
2
1907
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 pointer to the child class and call the function on_mdiactivate() using this pointer. For some reason, the program executes MDIChildClass::on_mdiactivate() and not Document::on_mdiactivate(). Why? on_mdiactivate() is a virtual function in...
8
1617
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
6600
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 written in C++ and it's calling a java application. This application displays a window and pushing a button is calling back the c++-plugin again.
15
11761
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 performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
5
3414
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 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
4
2242
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 do is call a generically named public sub in the top-most sub form in the panel. I have the name of the top-most form as a string (eg. g_TopForm = "frmCustomers") and I can reference the form with:
3
8630
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 function called "OnPrintMsg" from my dialog class called "MyAppDlg.h". The function needs to be called from another class called "Client.cpp". The Client class (derived from the CSockets class) exists as described below.
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.