View Single Post
Old 05-05-2005, 07:51 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
First rule #1:
For operator >> and << always return the stream at the end:
Code:
istream& / ostream& operator<</>>(istream/ostream& iostr, T& t)
{
   //code
   return iostr;
}
Now for your extraction operator:
Are you sure what you are doing? What are you trying to achieve? Something is fishy about overloading an extraction operator for the enum type... do you see why?

As for your answer:
What means this:
Code:
#include <iostream>
#include <ios>

using namespace std;

enum AnEnum {A, B, C, D};

int main()
{
  AnEnum MyEnum;
  //What???
  cin>>MyEnum;
  
  //Optional. Depends on IDE: prevents "console flashing".
  cin.get();
  return 0;
}
And this?
Code:
  //Come again?
  if(MyEnum == "Hi")
  {
      //Whatever.
  }
With tons of fantasy, I maybe could find a use for overloading the extraction operator for enum types. But you may ask yourself how sane that is .
Many employers threaten to fire programmers if they come up with such code. You have been warned.
__________________
Valmont is offline   Reply With Quote