Newbie Question: Function of a class keeps "forgetting" data thats declared inside class

S

Snoeys Andy

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
 
S

Stewart Gordon

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.
 
W

White Wolf

Snoeys said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top