Thursday, 22 August 2013

error C2512 no appropriate default constructor available

error C2512 no appropriate default constructor available

ok so im having this issue involving two classes.
Dice.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;
};
Dice.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();
}
Whenever I try and compile I get this error:
Error 2 error C2512: 'Dice' : no appropriate default constructor
available
If I create another constructor for Dice with the format void Dice(void);
it works just fine.
Any help would be greatly appreciated

No comments:

Post a Comment