繁体   English   中英

我收到错误消息“ Pokemon.cpp:11:18:错误:没有对象就无法调用成员函数'int Dice :: roll()'”

[英]I'm getting error “Pokemon.cpp:11:18: error: cannot call member function ‘int Dice::roll()’ without object”

宠物小精灵战斗模拟器

我正在构建一个简单的战斗模拟器。 它将能够为HP,攻击级和防御级提供用户输入。

Pokemon::Pokemon() {
healthPoints = attackL = defL=0;
    std::string Pname= "";
    d20=Dice(20);
    d6=Dice(6);

我有4个文件Pokemon.h,Pokemon.cpp,Dice.h,Dice.cpp。 口袋妖怪头文件包含

#include <iostream>
#include <string>
#include "Dice.h"


class Pokemon {

    private:
        int healthPoints, attackL, defL;
        #include <iostream>
std::string Pname;
        Dice d20;
        Dice d6;

    public:
        Pokemon();
        bool attack(Pokemon& opponent);
        void userBuild();
} ;

Pokemon.cpp使用Pokemon类来“ 构建 ”用户的口袋妖怪。 我卡住的部分是尝试使用时

Pokemon::bool attack(){
d20=Dice.roll()

}

我收到一个错误“ Pokemon.cpp:13:10:错误:'bool'之前的预期不合格ID

这是有关“布尔攻击”应该做什么的说明

布尔攻击(口袋妖怪和对手)

如果攻击者的AttackLevel + attackBonus大于防御者的>> defenseLevel + defenseBonus,请使用d20来为and AttackBonus和DefenceBonus滚动随机值,然后对伤害进行滚动。 否则,如果攻击着陆,掷出三个d6,将其累加,则攻击会丢失,这就是损害显示样本运行中反映的所有攻击信息,仅当对手因攻击而死亡时才返回true,否则返回false

实现成员函数的语法是

bool Pokemon::attack(Pokemon& opponent){
...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM