Skip to main content
gamedev.net
🔒 Locked

Somewhat Simple Question

Started by Gf11speed 12 replies 300+ views
Original Post
Gf11speed
Gf11speed
What is wrong with this code? For some reason, the variables that I set in the Check() function are not set after the function ends. So I lose all my dad after the function returns. if(......) { RaceHorse.BestTime8Furlong.Check(RACE_CLOCK) } Inside the ''BestTime8Furlong'' structure, the Check() looks like this: void Check(RACE_CLOCK race_clock) { iBestTimeMinutes = race_clock.BestTimeMinutes; iBestTimeSeconds = race_clock.BestTimeSeconds; fBestTimeMilliseconds = race_clock.BestTimeMilliseconds; } What am I doing wrong? Thanks. *====================* http://www.syntasoft.com *=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Gf11speed
Gf11speed
But I''m not setting RACE_CLOCK, I''m setting the other variables. So would that matter?

*====================*
http://www.syntasoft.com
*=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Vendayan
Vendayan
Need more info I think, if the rest of the code looks like the way I would have made it that little tidbit should work. So I think your problem doesn''t lie in that code.

Is iBestTimeMinutes a member of BestTime8Furlong?

~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
SabreMan
SabreMan
quote:
Original post by Gf11speed
What is wrong with this code?

It''s not adequate for diagnosing your actual problem. Are you able to put together a small program that exhibits the problem?
quote:

So I lose all my dad after the function returns.

That must be terrible. When was the last time you saw him?


[C++ FAQ Lite | ACCU | Boost | Stroustrup on Learning C++]
benjamin bunny
benjamin bunny
^_^ It looks pretty screwed to me.
presumably RACE_CLOCK is a type, judging by the function definition, so why is he passing a type to the function? I suggest the poster gets himself a book on learning C/C++.

____________________________________________________________
www.elf-stone.com
Gf11speed
Gf11speed
I forgot to mention that the variables:
iBestTimeMinutes
iBestTimeSeconds
fBestTimeMilliseconds

are all members of the ''BestTime8Furlong'' structure.


I am calling the BestTime8Furlong.Check() function to change local variables to the ''BestTime8Furlong'' function.

*====================*
http://www.syntasoft.com
*=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
benjamin bunny
benjamin bunny
1. Pass the object by address or reference
2. Pass the object, not the type, as you appear to be doing.

Passing by address (note also, the OBJECT is passed, not the TYPE)

    
//somewhere in the code

RACE_CLOCK rc;

if(......)
{
RaceHorse.BestTime8Furlong.Check(&rc)
}


void Check(RACE_CLOCK * race_clock)
{
iBestTimeMinutes = race_clock.BestTimeMinutes;
iBestTimeSeconds = race_clock.BestTimeSeconds;
fBestTimeMilliseconds = race_clock.BestTimeMilliseconds;
}



3. Buy a book and learn C++



____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on April 18, 2002 7:13:58 PM]
Gf11speed
Gf11speed
benjamin bunny:

1) Thanks for the help
2) I tried that already and it didn''t work
3) Learn to stop being an asshole

*====================*
http://www.syntasoft.com
*=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
benjamin bunny
benjamin bunny
I thought it was more polite than just RTFM.

By the way, passing the type will not work. I don't know what exactly you're doing wrong, but passing the type is just incorrect. You should either pass a pointer or a reference to the object.
____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on April 19, 2002 6:54:10 AM]
Gf11speed
Gf11speed
I think I figured it out. I just did it a different way. Instead of using that function, I used another one that is not in the struct.



*====================*
http://www.syntasoft.com
*=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Gf11speed
Gf11speed
And doing a great job at it indeed my friend...

*====================*
http://www.syntasoft.com
*=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.