3
我不能为我的生活弄清楚这一点。级别数据会员无法访问
int Warrior :: attack()
{
int hit;
srand(time(0));
if (Warrior.weapon == 6)
int hit = rand() % 5 + 1;
else if (Warrior.weapon == 7)
int hit = rand() % 7 + 4;
else if (Warrior.weapon == 8)
int hit = rand() % 7 + 9;
else if (Warrior.weapon == 9)
int hit = rand() % 7 + 14;
else if (Warrior.weapon == 10)
int hit = rand() % 7 + 19;
std::cout<< "You hit " << hit <<"!\n";
return hit;
}
我得到这个错误:Error C2059: syntax error : '.'
(也是我知道我应该使用,而不是一个else if
声明switch
)
谢谢。
没有看到你的类定义是不可能的,但你可能需要'this-> weapon',或者像@chris所说的那样,如果它是静态的,'Warrior :: weapon'。 – slugonamission
另外,你只需要一次种子,而不是每次击中。 – slugonamission
你重新声明了5次“命中”。你只是想要一个任务。删除这些行上的'int'关键字。你应该在程序执行期间只调用'srand(time(0))'一次*。 –