[C++] Omitted return statement
From: Gary Labowitz (glabowitz_at_comcast.net)
Date: 04/29/04
- Next message: Old Wolf: "Re: nested for loops, homework help"
- Previous message: David White: "Re: Newbie OOP question"
- Next in thread: Arthur J. O'Dwyer: "Re: [C++] Omitted return statement"
- Reply: Arthur J. O'Dwyer: "Re: [C++] Omitted return statement"
- Reply: Sumit Rajan: "Re: [C++] Omitted return statement"
- Reply: Chris \( Val \): "Re: [C++] Omitted return statement"
- Reply: Francis Glassborow: "Re: [C++] Omitted return statement"
- Reply: P P: "Re: [C++] Omitted return statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Apr 2004 20:53:05 -0400
One of my students overloaded the operator<< function for use on a
UDT. His code did not include a return statement even though the
header calls for an ostream& as the return type. The program works
anyway for chained output. How can this be? If it's undefined
behavior, are we just getting unlucky?
Using g++ 3.2 on W2K box. (You may need to include cstdlib)
TIA
--
Gary
code follows:
#include <iostream>
using namespace std;
class PhoneCall
{
string phoneNumber;
double rate;
int time;
public:
bool operator==(PhoneCall Fraction1);
friend istream& operator>>(istream &dicky, PhoneCall
&ugh);
friend ostream& operator<<(ostream &dicky, PhoneCall ugh);
};
ostream& operator<<(ostream &dicky, PhoneCall ugh)
{
dicky << "the phone number was" << ugh.phoneNumber << " it costs
dis much" << ugh.rate*ugh.time << endl;
}
istream& operator>>(istream &dicky, PhoneCall &ugh)
{
cout << "enter da number";
dicky >> ugh.phoneNumber;
cout << "enter da TIme: ";
dicky >> ugh.time;
cout << "feast on the rate: ";
dicky >> ugh.rate;
return (dicky);
}
int main ()
{
int count =0 ;
PhoneCall a, b, c;
cin >> a >> b >> c;
cout << a <<"Here is b " << b << c;
system("Pause");
return 0;
}
- Next message: Old Wolf: "Re: nested for loops, homework help"
- Previous message: David White: "Re: Newbie OOP question"
- Next in thread: Arthur J. O'Dwyer: "Re: [C++] Omitted return statement"
- Reply: Arthur J. O'Dwyer: "Re: [C++] Omitted return statement"
- Reply: Sumit Rajan: "Re: [C++] Omitted return statement"
- Reply: Chris \( Val \): "Re: [C++] Omitted return statement"
- Reply: Francis Glassborow: "Re: [C++] Omitted return statement"
- Reply: P P: "Re: [C++] Omitted return statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]