Reputation: 1
I have to create a program where a chutist jumps from a plane. The user inputs the altitude and the time when the chutist will open its parachute. I haven't finished all my code, just wanted to know if it can run before I go any further but I always get this error (Conversion from 'int' to non-scalar type 'Point" requested). We are also using the Hortsmann libraries which I am very new to. Anyone knows what this error means and what can I do to fix any error of this kind? If you don't understand my question, please tell me. Here is the code: #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);
}
Upvotes: 0
Views: 2476
Reputation: 1
For future references, it was because of the equal sign on the following code:
[Point top = (jumpman.get_x(), jumpman.get_y());
Circle c = (top, 10);]
I guess since we are creating the point and the circle we aren't supposed to use an equal sign.
Upvotes: 0
Reputation: 4196
The error occurs in the lines
Point top = (jumpman.get_x(), jumpman.get_y());
Circle c = (top, 10);
where you intend to create instances of Point
and Circle
. Which we don't have the corresponding headers, by common sense it's safe to assume that those classes have ctor's that take obvious parameters (int, int)
and (Point, int)
. So, the correct way to create an object of a class is either this
Point top(jumpman.get_x(), jumpman.get_y());
Circle c(top, 10);
or
Point top = Point(jumpman.get_x(), jumpman.get_y());
Circle c = Circle(top, 10);
which would results in calls to the appropriate constructors.
Your code results in the following. The expression (jumpman.get_x(), jumpman.get_y())
evaluates to the rightmost jumpman.get_t_y()
, that's how the comma operator works. Thus, the compiler concludes that you want to construct a Point
from a single int
, which is impossible, since there (obviously) is no such constructor or conversion operator. Same for the second line, with different constructor parameters.
Upvotes: 1