Jump to content
  • Advertisement
Sign in to follow this  
Faded-Maximus

Compiling a text game

This topic is 4402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I am trying to compile a game I wrote in Visual C++ 6. I get this as an error message: Compiling... tic-tac-toe.cpp tic-tac-toe.cpp(213) : error C2374: 'move' : redefinition; multiple initialization tic-tac-toe.cpp(196) : see declaration of 'move' Error executing cl.exe. I realize in my code that I have redefined move = 0 twice, once on line 196 and once on line 213. Why isn't this allowed? and how can I prevent this from happening? Any help is greatly appreciated.
	// If computer can win on next move, make that move
	for(int move = 0; move < board.size(); ++move)
	{
		if (isLegal(move, board))
		{
			board[move] = computer;
			if (winner(board) == computer)
			{
				cout << move << endl;
				return move;
			}
			// done checking this move, undo it
			board[move] = EMPTY;
		}
	}

	// If human can win on enxt move, block that move
	char human = opponent(computer);
	for(int move = 0; move < board.size(); ++move)
	{
		if (isLegal(move, board))
		{
			board[move] = human;
			if (winner(board) == human)
			{
				cout << move << endl;
				return move;
			}
			// done checking this move, undo it
			board[move] = EMPTY;
		}
	}

Share this post


Link to post
Share on other sites
Advertisement
using move that way should be legal, they are not in the same scope. Do you have move defined anywhere before this that would be in the scope of move?

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by Faded-Maximus
Why isn't this allowed?

it is allowed in standard c++. the problem is that vc++ 6 is pre-standard and a variable declared in a for loop doesn't go out of scope when exiting the loop like it's supposed to.
Quote:

how can I prevent this from happening?

i'd suggest upgrading. visual c++ 2005 express is a free download.

Share this post


Link to post
Share on other sites
Edit: Beaten to it. Oh well.

The problem is that you're using VC 6, which does not correctly follow the C++ standard.
If you're determined to continue using VC 6 for some reason (which you probably shouldn't be - more recent and much better compilers, both from Microsoft and others, are available for free), then you can solve the problem by defining the move variable once, before the first for loop, and then only initializing it within each loop, rather than actually declaring it within each loop, ie,

int move;
for (move = 0; ...)
...
...
for (move = 0; ...)
...




But otherwise, go and download VC++ Express 2005.

John B

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!