I'm having a problem with an assignment. I'm using a class that stores a point on a Cartesian plane, and deriving a class from it called circletype. Circletype has an additional member for the radius and a function to find the area.
My problem is with the constructor. The error is
point.cpp In constructor `circletype::ci rcletype(double , double, float)':
no matching function to point:point
candidates are: point:point (const point&)
point point(double, double)
The constructor for point is
The constructor for circletype is
Here is the code for point.h in its entirety.
Here is point.cpp
It's my first time with derived classes, and I'm really not sure what I'm doing wrong. I'd appreciate any advice.
My problem is with the constructor. The error is
point.cpp In constructor `circletype::ci rcletype(double , double, float)':
no matching function to point:point
candidates are: point:point (const point&)
point point(double, double)
The constructor for point is
Code:
point::point(double initial_x, double initial_y)
{
x = initial_x; // Constructor sets the point to a given position.
y = initial_y;
}
Code:
circletype::circletype(double initial_x, double initial_y, float radius_value)
{
set_x(initial_x);
set_y(initial_y);
radius = radius_value;
}
Here is the code for point.h in its entirety.
Code:
class point
{
public:
// CONSTRUCTOR
point(double initial_x, double initial_y);
// MODIFICATION MEMBER FUNCTIONS
void shift(double x_amount, double y_amount);
void rotate90( );
void set_x(double x_amount);
void set_y(double y_amount);
// CONSTANT MEMBER FUNCTIONS
double get_x( ) const { return x; }
double get_y( ) const { return y; }
private:
double x; // x coordinate of this point
double y; // y coordinate of this point
};
class circletype:public point
{
public:
//CONSTRUCTOR
circletype(double initial_x, double initial_y, float radius_value);
//MODIFICATION MEMBER FUNCTIONS
void set_radius(float radius);
//CONSTANT MEMBER FUNCTIONS
float get_radius() const;
private:
float radius;
};
Code:
#include "point.h"
point::point(double initial_x, double initial_y)
{
x = initial_x; // Constructor sets the point to a given position.
y = initial_y;
}
void point::shift(double x_amount, double y_amount)
{
x += x_amount;
y += y_amount;
}
void point::rotate90( )
{
double new_x;
double new_y;
new_x = y; // For a 90 degree clockwise rotation, the new x is the original y,
new_y = -x; // and the new y is -1 times the original x.
x = new_x;
y = new_y;
}
void point::set_x(double x_amount)
{
x = x_amount;
}
void point::set_y(double y_amount)
{
y = y_amount;
}
circletype::circletype(double initial_x, double initial_y, float radius_value)
{
set_x(initial_x);
set_y(initial_y);
radius = radius_value;
}
Comment