ship.cpp:27:error:no matching function for call to âShi
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/05/09 15:18:27
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: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];
}
s = new Ship[s->length];是创建了一个Ship对象数组,这时候会调用Ship的构造函数,对Ship进行初始化,此时调用的是无参的构造函数,但是你的程序中没有这样的够构造函数,所以出错了.
解决办法:
1、在Ship类中,添加无参构造函数.
2、在创建对象数组时,创建有参数的.
解决办法:
1、在Ship类中,添加无参构造函数.
2、在创建对象数组时,创建有参数的.
ship.cpp:27:error:no matching function for call to âShi
Fatal error: Call to a member function num_rows() on a non-o
Call to undefined function mysql_connect()
Expected to ship no later
vc++ error C2064:term does not evaluate to a function
英语翻译Our proposal is for you to ship to us the following no c
As no one is seriously hurt,------is no need to call for a d
Call to a member function persist() on a non-object
Error AdvSim No nets, nothing to simulate
define subscreen for function group - how to?
ship international call
error C2064: term does not evaluate to a function错误,求救