🔒 Locked
Somewhat Simple Question
Advertisement
Original Post
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
*=======================*
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++]
^_^ 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
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
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
*=======================*
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
*=======================*
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)
3. Buy a book and learn C++
____________________________________________________________
www.elf-stone.com
[edited by - benjamin bunny on April 18, 2002 7:13:58 PM]
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]
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]
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement