#### Archived

This topic is now archived and is closed to further replies.

# What anyone tell me what is wrong with my code please?

## Recommended Posts

jimywang    100
Here is a constructor for my game_control class. game_control::game_control(): Player(1) { for(int i = 0;i < 3;++i) for(int j = 0;i < 3;++j) gamebroad [j] = 0; }//game_control and I have the follow error: ISO C++ forbids defining types within return type return type sepecification for constructor incvalid What does this error mean? [edited by - jimywang on April 28, 2003 6:26:48 PM] [edited by - jimywang on April 28, 2003 6:30:20 PM]

##### Share on other sites
owl    376
is that the actual source? Or a rip of it?

I got that error when I want to return the value of a variable that was defined inside the for statement:
{for (int i=0;i<1;i++)  pepe(i);return i;}

I solved it doing this
{int i;for (i=0;i<1;i++)  pepe(i);return i;}

[edited by - xaxa on April 28, 2003 6:22:25 PM]

stodge    144

##### Share on other sites
jimywang    100
And that bunch of code is from a .cpp file.
and i also have a .hpp file for it.
that is just:
public:
game_control();

##### Share on other sites
rypyr    252
"return type sepecification for constructor invalid"

Are you trying to return a value in your Player(int) constructor?

Also, shouldn''t gamebroad be spelled gameboard?

Regards,
Jeff

##### Share on other sites
Yohumbus    152
hmm all I can think of is you put a return value in the constructors declaration.

btw to save some headache later shouldn''t

for(int i = 0;i < 3;++i)
for(int j = 0;i < 3;++j)

have a j in the conditional on the second loop

##### Share on other sites
NewbieGamer    122
Like most of the responses have mentioned, you might be having some return type specified just before your constructor''s defintion. [something like void, int or other type before your constructor''s definition].

The other thing to note is that your game_board [or game_broad] is a two-dimensional array, right?. So according to VC++ compiler, this will throw an error while compiling because you are trying to set the address with some constant number (0). This is hazardous.....
Depending on the compiler you should get an error...... if not your app would crash later on.... [if the compiler is very forgiving!!!].

Your loop should be something like
for(int x=0; x for(int y=0; y game_board[x][y]=0;

Cheers!!!
V

##### Share on other sites
NewbieGamer    122
Oooppsss!!!
Apologies..... Don''t know how it lost the actual code that i posted...

for(x=0; x < m; x++)
for(y=0; y < n; y++)
game_board[x][y]=0;

##### Share on other sites
TheMuuj    122
quote:
Original post by rypyr
"return type sepecification for constructor invalid"

Are you trying to return a value in your Player(int) constructor?

Also, shouldn''t gamebroad be spelled gameboard?

Regards,
Jeff

Maybe gamebroad represents a female player in the game, and he is just a sexist programmer.

You could even have gamefemale as a base class, and gamegirl, gamechick, gamebroad, and gamewoman could all be derived classes. I won''t even get into gameskank and whatnot.

Which brings up a good subject...

Sometimes I wish there was a spell checker in programming environments to prevent that kind of mistake. Perhaps it could check all variable and function declarations, convert the CamelCaseIdentifiers (or underscored_identifiers) into individual words, and look them up in a spelling dictionary. It wouldn''t even have to be a real-time spellchecker (the ones that underline words), but one that you run every once in a while. When a change is made, all other occurances of that same mistake could be replaced.

Sounds like a nifty project to implement in VS.NET. I wager it would be fairly easy to do for C# programs. C++ might be trickier, but it would be useful, no?

--TheMuuj

##### Share on other sites
rypyr    252
quote:
Original post by NewbieGamer
Oooppsss!!!
Apologies..... Don''t know how it lost the actual code that i posted...

for(x=0; x < m; x++)
for(y=0; y < n; y++)
game_board[x][y]=0;

The reason this happened is because you used i as your variable and [, then i, then ] got interpretted as italics in the gamedev forum editor (see how the rest of your code is in italics).

So your code is right when it comes to the array (someone else pointed out it was wrong), it just didn''t paste nicely in this forum.

Did you fix it? Was it your Player constructor?

Regards,
Jeff

##### Share on other sites
jimywang    100
Ok,I know where I have done wrong.I forget the "," after the "}".
Thank you for ur guess help and sorry about my spelling error.