這裏聲明是標題:尺寸()函數編圖的錯誤,說大小()不在此範圍
#ifndef SHIP_H
#define SHIP_H
class Ship
{
public:
virtual ~Ship(void) {}
virtual const char *name(void) const = 0;
virtual int size(void) const = 0;
int getX(int i) const;
int getY(int i) const;
void print(void) const;
bool includes(int x, int y);
int level(void) const;
void decreaseLevel(void);
static Ship *makeShip(char ch, int x1, int y1, int x2, int y2);
protected:
void setPos(int a1, int b1, int a2, int b2);
int lev;
private:
bool checkConfig(int x1, int y1, int x2, int y2);
int x1,y1,x2,y2;
};
class AircraftCarrier : public Ship
{
public:
AircraftCarrier(int x1, int y1, int x2, int y2);
virtual const char *name(void) const;
virtual int size(void) const;
};
class BattleShip: public Ship
{
public:
BattleShip(int x1, int y1, int x2, int y2);
virtual const char *name(void) const;
virtual int size(void) const;
};
class Cruiser: public Ship
{
public:
Cruiser(int x1, int y1, int x2, int y2);
virtual const char *name(void) const;
virtual int size(void) const;
};
class Destroyer: public Ship
{
public:
Destroyer(int x1, int y1, int x2, int y2);
virtual const char *name(void) const;
virtual int size(void) const;
};
#endif
這裏是在派生類中的一個我的大小功能,爲每個接口的所有大小功能四類被格式化同時,每個均具有不同的尺寸的值:
int AircraftCarrier::size(void) const
{
int size = 5;
return size;
}
,這裏是其中i使用尺寸是其中所述錯誤的引用:
bool checkConfig(int x1, int y1, int x2, int y2)
{
//int s,spaces;
//s = size();
if (x1 == x2)
{
if(size()-1 == y2-y1)
{
return true;
}
else
return false;
}
else if (y1 == y2)
{
if(size()-1 == x2-x1)
{
return true
}
else
return false;
}
else
return false;
}
我會比函數變量使用不同的名字...... –