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

Discussion in 'C++' started by Snoeys Andy, Sep 12, 2003.

  1. Snoeys Andy

    Snoeys Andy Guest

    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
     
    Snoeys Andy, Sep 12, 2003
    #1
    1. Advertising

  2. 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.
     
    Stewart Gordon, Sep 12, 2003
    #2
    1. Advertising

  3. Snoeys Andy

    White Wolf Guest

    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
     
    White Wolf, Sep 12, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Sherman

    Forgetting how to use vec

    Aaron Sherman, Feb 5, 2004, in forum: Perl
    Replies:
    0
    Views:
    605
    Aaron Sherman
    Feb 5, 2004
  2. DC Gringo
    Replies:
    4
    Views:
    4,848
    mfreidge
    Dec 17, 2007
  3. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,606
    Jon Paal
    Feb 5, 2006
  4. Replies:
    8
    Views:
    346
    James Kanze
    Nov 5, 2008
  5. DC Gringo
    Replies:
    3
    Views:
    219
    DC Gringo
    Sep 14, 2004
Loading...

Share This Page