-3

Here is my player class

#pragma once

#include <raylib.h>
#include "SpriteManager.h"
#include "Sprite.h"
#include "Utils.h"
#include "DashAbility.h"
#include "AbilityHolder.h"

class Player : public Sprite
{
public:
    float moveSpeed = 300.0f;

    DashAbility ability1;

    AbilityHolder abilit1Holder;

    void init(SpriteManager &spriteManager)
    {
        texture = spriteManager.player;
        x = GetScreenWidth() / 2.0f;
        y = GetScreenHeight() / 2.0f;
        width = texture.width;
        height = texture.height;

        ability1.init(3.0f, 1.0f, 1000.0f);
        abilit1Holder.init(ability1, KEY_E);
    }

    void update(Camera2D &camera)
    {
        vx = heldKeys(KEY_A, KEY_D) * moveSpeed;
        vy = heldKeys(KEY_W, KEY_S) * moveSpeed;

        if (vx > 0.0f)
            fx = 1;
        if (vx < 0.0f)
            fx = -1;

        abilit1Holder.update(this);

        x += vx * GetFrameTime();
        y += vy * GetFrameTime();

        camera.target = (Vector2){x, y};
    }
};

And here is my AbilityHolder class

#pragma once

#include <raylib.h>
#include "Ability.h"

class AbilityHolder
{
public:
    int key;

    float cooldownTimer = 0.0f;
    float activeTimer = 0.0f;

    bool isCooldown = false;
    bool isActive = false;

    Ability ability;

    void init(Ability _ability, int _key)
    {
        ability = _ability;
        key = _key;
    }

    void update(Sprite &target)
    {
        if (IsKeyPressed(key) && !isCooldown && !isActive)
        {
            isActive = true;
        }

        if (isActive)
        {
            ability.active(target);
            activeTimer += GetFrameTime();
            if (activeTimer > ability.activeTime)
            {
                isActive = false;
                isCooldown = true;
                activeTimer = 0.0f;
            }
        }

        if (isCooldown)
        {
            cooldownTimer += GetFrameTime();
            if (cooldownTimer > ability.cooldownTime)
            {
                isCooldown = false;
                cooldownTimer = 0.0f;
            }
        }
    }
};

Inside update function of Player class, I want to call ability1Holder update function and it takes 1 argument, and I put "this" inside it. But code blocks gives me this error:

include\Player.h|41|error: no matching function for call to 'AbilityHolder::update(Player*)'|

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
  • Pop quiz: in C++, is `this` a pointer or a reference? What is the parameter to the `update()` function, a pointer or a reference? And after you answer these questions, then what, exactly, are you unsure about? – Sam Varshavchik Jan 19 '23 at 03:31
  • type mismatch you're passing pointer to a function which takes a reference as a parameter. – Swift - Friday Pie Jan 19 '23 at 03:34

1 Answers1

1

Try changing abilit1Holder.update(this); to abilit1Holder.update(*this);.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
fan
  • 21
  • 1