While practicing classes in winapi, how do I export to the getter setter or change the value of the imported variable?

Asked 2 years ago, Updated 2 years ago, 108 views

// Declare score variables in the Player class
m_nScore;

Player::Init()
{
    m_nScore = 0;
}

// Getter
    int GetPlayerScore() { return m_nScore; }

// Dynamic Assignment
m_pObjects = new Objects;
m_pObjects->SetPlayer(m_pPlayer);

// Objects class wants to increase or decrease when conditions are met
class Objects
{
private:
    Player* m_pPlayer;

public:
    void SetPlayer(Player* pl) { m_pPlayer = pl; }
}

Objects::Update()
{
    RECT; // Temporary value

    if (intersectRect(&rt, &m_pPlayer->GetPlayerVector.rt, &m_vecEnemys.rt))
    {
        m_vecEnemys.erase(m_vecEnemys.begin() + i);    
        m_pPlayer->GetPlayerScore() + 50; // This does not work
    }
}

Exporting or importing into another class as a getter setter
It's possible, but how can I change the value I brought?

c++ winapi class getter setter

2022-09-22 08:29

1 Answers

Try a reference.


2022-09-22 08:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.