Hi, i have a problem, i am using a library given by my university to create a game, these are my classes and cpp files, and i am getting this error: error C2512: 'Board' : no appropriate default constructor available, pls help.
class Board
{
protected:
GWindow &Gwin;
int coorX;
int coorY;
int x,y,x2,y2,x3,y3,d;
int BoxX[20];
int BoxY[20];
bool gotBox;
//int BlackX[5];
//int BlackY[5];
public:
Board(GWindow &);
void createBoard();
void selectBox();
};
#include "board.h"
class Ship : public Board
{
private:
GWindow &Gwin;
string shipName;
int shipX,shipY;
int shipHP;
int shipType;
int i;
public:
Ship(GWindow &);
void getShip(string,int,int,int);
void drawShip();
void moveShip();
};
the board.cpp file
#include "stdafx.h"
#include "gwin.h"
using namespace std;
Board::Board(GWindow &g) :
Gwin(g)
{
coorX=0;
coorY=0;
x=0;
y=0;
gotBox=false;
d=0;
}
void Board::createBoard()
{
for(int i =0;i<16;i++)
{
BoxX[i]=x;
x=x+40;
}
for(int i=0;i<12;i++)
{
BoxY[i]=y;
y=y+40;
}
Gwin.setPenColour(WHITE);
for(int i = 0; i<12 ;i++)
{
for(int u = 0; u<16;u++)
{
Gwin.outlineRectangle(BoxX[u],BoxY[i],BoxX[u]+40,BoxY[i]+40);
}
}
Gwin.refresh();
}
void Board::selectBox()
{
if(Mouse.isLeftDown()==true) //to get the correct box coordinates
{
coorX=Mouse.x;
coorY=Mouse.y;
for(int i = 0; i<16 ;i++)
{
if(coorX<=BoxX[i])
{
x2=BoxX[i-1];
for(int u = 0; u<12; u++)
{
if(coorY<=BoxY[u])
{
gotBox = true;
y2=BoxY [u-1];
break;
}
}break;
}
}
}
// int *BlackY = new int[5];
// int *BlackX = new int[5];
/*if(gotBox)
{
BlackX[d]=x2;
BlackY[d]=y2;
Gwin.setPenColour(RED);
Gwin.outlineRectangle(BlackX[d-1],BlackY[d-1],BlackX[d-1]+40,BlackY[d-1]+40);
Gwin.setPenColour(YELLOW);
Gwin.outlineRectangle(BlackX[d],BlackY[d],BlackX[d]+40,BlackY[d]+40);
gotBox = false;
d++;
}
Gwin.refresh();*/
}
and the ship.cpp file:
#include "ship.h"
#include "stdafx.h"
using namespace std;
Ship::Ship(GWindow &g) :
Gwin(g)
{ //ERROR POINTS TO HERE, BUT ISNT THIS A CONSTRUCTOR?
i=0;
shipX=0;
shipY=0;
shipHP=0;//counts how many times the ship has been hit
}
void Ship::getShip(string name,int t, int x, int y)
{
shipType=t;//1 = battleship, 2 = battlecruiser
shipX=x;
shipY=y;
shipName=name;
}
void Ship::drawShip()
{
int xsize=40;
int ysize=40;
if(shipType==1)
{
GImage smallShip("images\\smallShip.png");
//Gwin.drawImage(shipX,shipY,&smallShip);
GError ge = Gwin.drawImageScaled( shipX, shipY, xsize,ysize, &smallShip);
}
else if(shipType==2)
{
GImage longShip("images\\longShip.png");
//Gwin.drawImage(shipX,shipY,&longShip);
GError ge = Gwin.drawImageScaled( shipX, shipY, xsize,ysize, &longShip);
}
}
void Ship::moveShip()
{
int *tempX = new int[5];
int *tempY = new int[5];
if(x2==shipX && y2==shipY)
{
tempX[i]=x2;
tempY[i]=y2;
i++;
}
delete[] tempX;
delete[] tempY;
}
im trying to use inheritance to get the value from selectBox() to use in moveShip(), but the error keeps popping up. thanks for the help and any advice about the code too thx