argument of type `int (character::)()' does not match `int'

0

Witam! Pisząc aplikację konsolową napotkałem problem jak w temacie. Kod przedstawi jaśniej sprawę:

class character
{
    int hp;
    string name;
    int min_dmg;
    int max_dmg;
    int defense;
    int capacity;
    vector <item> items;

    public:
        character(int aHp, string aName, int aMin_dmg, int aMax_dmg, int aDefense, int aCapacity)
        {
            hp = aHp;
            name = aName;
            min_dmg = aMin_dmg;
            max_dmg = aMax_dmg;
            defense = aDefense;
            capacity = aCapacity;
            for (int i = 0; i < max_items; i++)
            {
                items.push_back(item("empty", 0));
            }
        }

        int getMin_dmg()
        {
            return min_dmg;
        }

        int getMax_dmg()
        {
            return max_dmg;
        }
};

int random(int min, int max)
{
    return min + rand() % (max - min + 1);
}

void battle(character &opponent1, character &opponent2)
{
    opponent1.setHp(random(opponent2.getMin_dmg, opponent2.getMax_dmg)); //tu ten błąd
}

Dlaczego tak się dzieje? Zwracany wynik getMax_dmg jest przecież typu int jak i sam max_dmg. To samo z getMin_dmg. Dlaczego nie mogę się odwołać do obiektu, wstawić jego wartości do drugiej funkcji?

0
opponent1.setHp(random(opponent2.getMin_dmg, opponent2.getMax_dmg)); //tu ten błąd

Zabrakło Ci nawiasów.

0

Ja oślepłem? Przecież są nawiasy po 2 bo 2 funkcję czyli razem 4 czyli tyle ile chyba byc powinno nie? W którym miejscu niby brakuje nawiasów?

0

Tak, oślepłeś. Nieświadoma ślepota wybiórcza. ;)

opponent1.setHp(random(   opponent2.getMin_dmg() /* <--- tutaj */   ,    opponent2.getMax_dmg()  /* <--- i tutaj */  ));

http://www.cplusplus.com/doc/tutorial/functions/

What you must always remember is that the format for calling a function includes specifying its name and enclosing its parameters between parentheses. The non-existence of parameters does not exempt us from the obligation to write the parentheses. For that reason the call to printmessage is:

printmessage ();

The parentheses clearly indicate that this is a call to a function and not the name of a variable or some other C++ statement. The following call would have been incorrect:

printmessage;

0

haha faktycznie zapomniałem, że to funkcję, już 2 raz dzisiaj tak zrobiłem. Dzięki :P

1 użytkowników online, w tym zalogowanych: 0, gości: 1