好的,所以我遇到了涉及两个课程的问题。
骰子.h:
#pragma once
#include <random>
using std::random_device;
using std::uniform_int_distribution;
class Dice
{
public:
Dice(int Sides);
int roll(void);
protected:
int nSides;
random_device generator;
uniform_int_distribution<int> distribution;
};
骰子.cpp:
#include "Dice.h"
Dice::Dice(int Sides)
{
nSides=Sides;
}
int Dice::roll(void)
{
random_device generator;
uniform_int_distribution<int> distribution(1,nSides);
return distribution(generator);
}
DmgCalc.h:
#pragma once
#include "CharSheet.h"
#include "Dice.h"
class DmgCalc
{
public:
DmgCalc(CharSheet P1, CharSheet P2);
bool Dodge();
int Attack();
int Roll();
protected:
int nP1Con, nP1Str, nP1Dex;
int nP2Con, nP2Dex, nP2Hlth;
Dice d6;
};
DmgCalc.cpp:
#include "DmgCalc.h"
DmgCalc::DmgCalc(CharSheet P1, CharSheet P2)
{
nP1Str=P1.getStr();
nP1Dex=P1.getDex();
nP2Con=P2.getCon();
nP2Dex=P2.getDex();
nP2Hlth=P2.getHlth();
Dice d6(6);
}
bool DmgCalc::Dodge()
{
return ((nP1Dex + d6.roll())-(nP2Dex + d6.roll()) > 0);
}
int DmgCalc::Attack()
{
nP2Hlth-=((nP1Str + d6.roll())-(nP2Con));
return nP2Hlth;
}
int DmgCalc::Roll()
{
return d6.roll();
}
每当我尝试编译时,都会收到此错误:
Error 2 error C2512: 'Dice' : no appropriate default constructor available
如果我使用格式为 Dice 创建另一个构造函数,void Dice(void);
它就可以正常工作。
任何帮助将不胜感激