Archived

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

jimywang

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

Recommended Posts

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 this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
"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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
Hi rypyr,
Thanks for explaining the nitty-gritty of the gamedev forum editor. Never thought about it. Wish there was a "Preview" option like most other newsgroups have.....
can''t ask more for now, though...
cheers!!!
V

Share this post


Link to post
Share on other sites