ship.cpp:27:error:no matching function for call to âShip::Ship()âship.cpp:12:note:candidates are:Ship::Ship(const Ship&)ship.cpp:7:note:Ship::Ship(point,direction,int)class 里的内容是:class Ship{private:int length;direction orientati

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 03:09:52
ship.cpp:27:error:no matching function for call to âShip::Ship()âship.cpp:12:note:candidates are:Ship::Ship(const Ship&)ship.cpp:7:note:Ship::Ship(point,direction,int)class 里的内容是:class Ship{private:int length;direction orientati
xT]OA+cL5+ }d)M HbƇeI֙IZ>#>@A,1A@>Z?Ɲmy/xg{ΙsO' rN7L! mBKL`Si\v&s m[>t\+"ܳ]qCNåq$viݚe 8 ;ѩf,*x~QU%m$0j⅞s DCpre,Ź* c(T9gHH՗D) =۝~飾ߦ(|Vg8cW[[?⡹|S/z -3SG&LɷAhy=ü`(E,8XG,_*nbkar18 N^s[𦑯+n­ /j]a=gr: "#cQ|uYgP<'J Q9!!*^.jbPduZcdś@4IߊjbƤOGxi\_ۗ)~IpRXu:`S-Z**bb9ޝ=t,KNx!&jڊ521U,_ j3fCr8

ship.cpp:27:error:no matching function for call to âShip::Ship()âship.cpp:12:note:candidates are:Ship::Ship(const Ship&)ship.cpp:7:note:Ship::Ship(point,direction,int)class 里的内容是:class Ship{private:int length;direction orientati
ship.cpp:27:error:no matching function for call to âShip::Ship()â
ship.cpp:12:note:candidates are:Ship::Ship(const Ship&)
ship.cpp:7:note:Ship::Ship(point,direction,int)
class 里的内容是:
class Ship
{
private:
int length;
direction orientation;
point origin;
PointCollection points;
PointCollection hits;
public:
Ship(point originPoint,direction orientationDirection,int lengthValue);
Ship(const Ship&);
bool containsPoint(const point& p) const;
bool collidesWith(const Ship* s) const;
void shotFiredAtPoint(const point& p);
bool isHitAtPoint(const point& p);
int hitCount() const;
const Ship& operator=(const Ship& s);
};
//然后这里报错!
bool Ship::collidesWith(const Ship* s)const{
s = new Ship[s->length];
}

ship.cpp:27:error:no matching function for call to âShip::Ship()âship.cpp:12:note:candidates are:Ship::Ship(const Ship&)ship.cpp:7:note:Ship::Ship(point,direction,int)class 里的内容是:class Ship{private:int length;direction orientati
s = new Ship[s->length];是创建了一个Ship对象数组,这时候会调用Ship的构造函数,对Ship进行初始化,此时调用的是无参的构造函数,但是你的程序中没有这样的够构造函数,所以出错了.
解决办法:
1、在Ship类中,添加无参构造函数.
2、在创建对象数组时,创建有参数的.