No matching function to call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jojestic
    New Member
    • Apr 2010
    • 2

    #1

    No matching function to call

    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
    Code:
    point::point(double initial_x, double initial_y)
        {
            x = initial_x;   // Constructor sets the point to a given position.
            y = initial_y;
        }
    The constructor for circletype is
    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;
        };
    Here is point.cpp
    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;
        }
    It's my first time with derived classes, and I'm really not sure what I'm doing wrong. I'd appreciate any advice.
  • akdemirc
    New Member
    • Sep 2008
    • 26

    #2
    As point class has no c'tor without parameters and when you create a Circletype you also create a point, what the compiler complains about is that it cannot decide how to create the point class without any parameters.. as far as i see you are using the first two parameters (double initial_x, double initial_y) to initalize the members inherited from point.. so simply you can pass these two to point class and let it do its job:

    circletype::cir cletype(double initial_x, double initial_y, float radius_value) :
    point (double initial_x, double initial_y)
    {
    radius = radius_value;
    }

    Comment

    • Jojestic
      New Member
      • Apr 2010
      • 2

      #3
      That was it. Thank you very much.

      Comment

      Working...