Topic: Enum


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sun, 23 Oct 1994 03:30:10 GMT
Raw View
subbarao@develop.bsis.com (Subbarao Chalavadi) writes:


>"check.C", line 9: warning: temporary used for non-const int & argument; no changes will be propagated to actual argument (anachronism)
>
>   enum color {red,green};
>
>   color mycolor[3];
>   cin >> mycolor[1];
>
>Why this warning comes up

Because there is no `operator >> (istream &, color &)' operator defined,
and because `operator >> (isteam &, int)' won't do the right thing.

>and can't i do a cin to the enum type variable ?

Yes, you can, you just need to write your own `operator >>'.
E.g. something like this should do the job:

 istream & operator >> (istream & is, color & c) {
  int i;
  is >> i;
  if (is) c = i;
  return is;
 }

--
Fergus Henderson - fjh@munta.cs.mu.oz.au




Author: subbarao@develop.bsis.com (Subbarao Chalavadi)
Date: 12 Oct 1994 19:17:16 GMT
Raw View
Hi,

  Below is my program, which when i try to compile gives me

"check.C", line 9: warning: temporary used for non-const int & argument; no changes will be propagated to actual argument (anachronism)




// check.c program

#include <iostream.h>

 main()
  {
   enum color {red,green};

   color mycolor[3];
   cin >> mycolor[1];
   cout << mycolor[1];
 }


Why this warning comes up and can't i do a cin to the enum type variable ?
I am using AT&T 3.1 CC compiler.

Pls email me your responses to subbarao@develop.bsis.com



S.C






p.s: My opinions don't reflect those of my employer's
~