• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Error on overloading IOStream operators in C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error on overloading IOStream operators in C++


  • Subject: Error on overloading IOStream operators in C++
  • From: Adam Spooner <email@hidden>
  • Date: Thu, 8 Feb 2007 20:46:06 -0500

Hello all!

I'm getting a "ISO C++ forbids declaration of 'ostream' with no type" error.

I'm overloading both istream and ostream operators (and get the error for both).

Here's what the code looks like:

friend ostream& operator <<( ostream& out, const term &rhs) {
// if the exponent is 0, then we simply output the coeff
if( rhs.exponent == 0)
out<<rhs.coefficient;
// if the exponent is 1, we output the coeff and x
else if( rhs.exponent == 1)
out<<rhs.coefficient<<"x";
// otherwise we output the coeff, x^, and it's exponent
else
out<<rhs.coefficient<<"x^"<<rhs.exponent;


return out;
}


friend istream& operator >>( istream$ in, term &rhs) {
// always get and set the coefficient
in>>rhs.coefficient;
// get the next character and see if it's x
get( ch);
if( ch == 'x') {
// if it is x, get the next character and
// see if it's the hat
get( ch);
if( ch == '^')
// if it is, set the exponent from the stream
in>>rhs.exponent;
// otherwise put the character back and set the
// exponent to 1
else {
putback( ch);
rhs.exponent = 1;
}
}
// otherwise put the character back and set the
// exponent to 0
else {
putback( ch);
rhs.exponent = 0;
}


return in;
}

Any help is greatly appreciated! Cheers!
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Error on overloading IOStream operators in C++
      • From: John Daniel <email@hidden>
  • Prev by Date: Re: Compile acts differently when run from terminal and in debugger???
  • Next by Date: otool and x86-64
  • Previous by thread: Re: Compile acts differently when run from terminal and in debugger???
  • Next by thread: Re: Error on overloading IOStream operators in C++
  • Index(es):
    • Date
    • Thread