Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Newbie Question: Function of a class keeps "forgetting" data thats declared inside class (http://www.velocityreviews.com/forums/t277583-newbie-question-function-of-a-class-keeps-forgetting-data-thats-declared-inside-class.html)

Snoeys Andy 09-12-2003 05:54 PM

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

Stewart Gordon 09-12-2003 06:14 PM

Re: Newbie Question: Function of a class keeps "forgetting" datathats declared inside class
 
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.


White Wolf 09-12-2003 06:15 PM

Re: Newbie Question: Function of a class keeps "forgetting" data thats declared inside class
 
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




All times are GMT. The time now is 04:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.