请求从'int'转换为非标量类型'Point'

时间:2016-02-04 00:55:54

标签: c++

我必须创建一个程序员,其中一名妓女从飞机上跳下来。用户输入高度和妓女打开降落伞的时间。我还没有完成我的所有代码,只是想知道它是否可以在我继续之前运行但是我总是得到这个错误(从'int'转换为非标量类型'Point'请求。)我们也在使用我很新的Hortsmann图书馆。任何人都知道这个错误意味着什么,我该怎么做才能解决这类错误?如果你不明白我的问题,请告诉我。     这是代码:     #include“ccc_win.h”     #include

using namespace std; 

class Chutist{
public:
 Chutist(); 
 Chutist(Point loc); //constructor where chutist always points up
 void display (int i, int s) const; //accessor function, displays chutist
 void move (int dx, int dy); // mutator function, moves chutist
private:
 Point jumpman;
 Point location; // location of chutist
};

//default

Chutist::Chutist(){
   location = Point (0, 0);
}

//construction of Chutist object at Point loc;

Chutist::Chutist(Point loc){
    jumpman = loc;
}

void Chutist::display(int i, int s) const{
  if (s < i){
     Point top = (jumpman.get_x(), jumpman.get_y());
     Circle c = (top, 10);
     cwin << c;
 }
}

void Chutist::move(int x, int dy){
}



int ccc_win_main(){
   cwin.coord(0, 2000, 2000, 0);
   int loc;
   int altitude = 0;
   int secondstoopen = 0;
   int velocity = 0;
   cout << "Please enter the altitude to jump at." << endl;
   cin  >> altitude;
   cout << "Please enter the time to open the parachute." << endl;
   cin  >> secondstoopen;
   Chutist jumper = Chutist(Point(0, altitude));
   jumper.display(secondstoopen);
}

2 个答案:

答案 0 :(得分:1)

错误发生在

行中
 Point top = (jumpman.get_x(), jumpman.get_y());
 Circle c = (top, 10);

您打算创建PointCircle的实例。我们没有相应的标题,根据常识,可以安全地假设这些类具有明显参数(int, int)(Point, int)的ctor。因此,创建类对象的正确方法是

Point top(jumpman.get_x(), jumpman.get_y());
Circle c(top, 10);

Point top = Point(jumpman.get_x(), jumpman.get_y());
Circle c = Circle(top, 10);

会导致调用适当的构造函数。

您的代码会产生以下结果。表达式(jumpman.get_x(), jumpman.get_y())计算到最右边的jumpman.get_t_y(),这就是逗号运算符的工作方式。因此,编译器得出结论,您希望从单个Point构造int,这是不可能的,因为(显然)没有这样的构造函数或转换运算符。第二行也是如此,具有不同的构造函数参数。

答案 1 :(得分:0)

对于将来的引用,这是因为[Point top =(jumpman.get_x(),jumpman.get_y());      圆c =(上,10);]。我想因为我们正在创建点和圆圈,我们不应该使用等号。

相关问题