I have two structs:

struct Vertex
{
   int row;
   int col;
   friend istream & operator >>(istream & is, Vertex & v)
   {
       char t[3];
       is >> t;
       v.col = t[0] - 'A';
       v.row = t[1] - '0';
       return is;
    }
};

struct Move
{
   Vertex orig;
   Vertex dest;
};

That compiles without error.

Now however I'd like to overload >> for Move like this:

friend istream & operator >> (istream & is, Move & m)
{
   is >> m.orig;
   is >> m.dest;
   return is;
}

That is, the >> for Move calls the >> for Vertex twice.

When I do that and try to compile my compiler throws an error message telling me that the >> operator isn't overloaded for Vertex eventhough the Vertex operator >> compiled fine before I added that version of the overloaded >> operator for Move.

Why doesn't the above version of >> for Move work?

Thanks.

struct Move
{
   Vertex orig;
   Vertex dest;
   friend istream & operator >> (istream & is, Move & m);
}; 

   istream & operator >> (istream & is, Move & m)
   {
    is >> m.orig;
       is >> m.dest;
          return is;
   }

That's what I tried, but the compiler didn't like it. I'll write it off as another quirk in VC++6.0 and go with what I have. Oh well.

Thanks for your input. I appreciate it.

>I'll write it off as another quirk in VC++6.0 and go with what I have.
Yes, it's a bug. Get a new compiler. You'll eventually get tired of the endless limitations, and the workarounds required to write anything but trivial C++.

Quick related question: Should I go with Dev C++ 4 or the beta version of 5?

The beta version seems very stable from the pounding I've given it so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.