Private class member not being set

This is a discussion on Private class member not being set within the C++ Programming forums, part of the General Programming Boards category; Right I've got an animation class - happy happy joy - and it has an inline function, SetUpdateDelay: Code: void ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Private class member not being set

    Right I've got an animation class - happy happy joy - and it has an inline function, SetUpdateDelay:

    Code:
    void SetUpdateDelay(float delay)
    {
        m_UpdateDelay = delay;
    }
    Looks pretty normal; what could go wrong, right? Wrong.

    I'm calling this function like so:

    Code:
        CAnimation explosion;
        explosion.AddFrame(m_ResourceMgr->GetTexture("./data/Explosion 1.png"));
        explosion.AddFrame(m_ResourceMgr->GetTexture("./data/Explosion 2.png"));
        m_Renderer->AddSceneObject("Explosion", explosion, CVector2<int>(100, 100));
        explosion.SetUpdateDelay(0.05f);
    If I step through it, CAnimation::m_UpdateDelay does indeed get set to 0.05. When I step through the update function, according to the debugger m_UpdateDelay is back to 250.0f (it's default value).

    What the hell am I doing wrong? I'm going to make the default value 0.05 right now and run that... otherwise I'm f'ing stumped.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> void SetUpdateDelay(float delay)

    That a friend of your explosion instance? OR shouldn't it be

    Code:
    void CAnimation::SetUpdateDelay(float delay)
    {
        m_UpdateDelay = delay;
    }
    Spaces, I see

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    May-be something like that? (It seems that you didn't copy and paste the function.)
    Code:
    void CAnimation::SetUpdateDelay(float delay)
    {
        float m_UpdateDelay = delay;
    }
    That would declare a new local variable and shadow the class member.

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Sorry I didn't say before, SetUpdateDelay is an inline member of CAnimation, as in I defined it in the class body. My bad.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    In AddSceneObject, are you adding a copy of explosion? If you are, and then you update the local version to 0.05, then the copy will still have the previous version. What do you mean by "When I step through the update function", what update function?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 25
    Last Post: 10-29-2007, 05:08 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Replies: 6
    Last Post: 04-27-2006, 11:55 AM
  4. Private Static class members
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2005, 07:37 AM
  5. help with template class using a template node
    By aciarlillo in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2005, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21