DEVELOP > c-Plus-Plus > Newbie Question: Function of a class keeps "forgetting" data thats declared inside class
| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Snoeys Andy" |
| Date: |
12 Sep 2003 12:54:10 PM |
| Object: |
Newbie Question: Function of a class keeps "forgetting" data thats declared inside class |
Hello,
I have hit into a problem with my latest program that creates a little
particle engine.
The engine itself is set up out of functions in a class.
It needs little "outside" info, only the mouse positions X and Y when
it is clicked.
I have an initialisation function that receives the mouse position,
and loads it into the memory assigned for the particles.
The memory is dynamically allocated in the classes constructor.
Then I have made a function that draws the particles to the screen and
edits their position.
The problem is, the second funtion keeps "forgetting" the updated
positions of the particles. It keeps returning to the values I got
from the mouse press.
I suppose I could bypass this problem by declaring and allocating the
memory globally, and then feed it to the function as a reference. But
that feels wrong.
How do I fix this?
Thanks!
Regards,
Snoeys Andy
.
|
|
| User: "White Wolf" |
|
| Title: Re: Newbie Question: Function of a class keeps "forgetting" data thats declared inside class |
12 Sep 2003 01:15:34 PM |
|
|
Snoeys Andy wrote:
Hello,
I have hit into a problem with my latest program that creates a little
particle engine.
The engine itself is set up out of functions in a class.
It needs little "outside" info, only the mouse positions X and Y when
it is clicked.
[SNIP]
How do I fix this?
Post the smallest possible compilable code, which shows your problem.
--
WW aka Attila
.
|
|
|
|
| User: "Stewart Gordon" |
|
| Title: Re: Newbie Question: Function of a class keeps "forgetting" datathats declared inside class |
12 Sep 2003 01:14:04 PM |
|
|
While it was 12/9/03 6:54 pm throughout the UK, Snoeys Andy sprinkled
little black dots on a white screen, and they fell thus:
Hello,
I have hit into a problem with my latest program that creates a little
particle engine.
The engine itself is set up out of functions in a class.
It needs little "outside" info, only the mouse positions X and Y when
it is clicked.
I have an initialisation function that receives the mouse position,
and loads it into the memory assigned for the particles.
The memory is dynamically allocated in the classes constructor.
Then I have made a function that draws the particles to the screen and
edits their position.
The problem is, the second funtion keeps "forgetting" the updated
positions of the particles. It keeps returning to the values I got
from the mouse press.
If they're declared within the function and not static, of course
this'll happen.
I suppose I could bypass this problem by declaring and allocating the
memory globally, and then feed it to the function as a reference. But
that feels wrong.
Why isn't the data simply in members of the class?
A code sample might help.
Stewart.
--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.
.
|
|
|
|

|
Related Articles |
|
|