Alex Rivera | Logout

error C2512: no appropriate default constructor available

Asked 2011-12-31T16:53:15.720
17

I am getting this annoying error and I don't know why =( ! This is the question , I solved it but I am having a problem with the constructor.

Write a program that defines a class called Circle that includes radius (type double) as data members. Provide a set and a get function for this data member. Ensure that the value entered by the user is valid and correct (greater than zero).
Include function members: a.function member that compute and return Diameter of the circle b.function member that compute and return Circumference of the circle c.function member that compute and return Area of the circle d.function member that Display all information of the circle e.constructor that initializes the data member. If the radius is not valid (i.e. less than zero) set it to zero.

the error I am facing :

error C2512: 'Circle' : no appropriate default constructor available

this is my code :

    #include <iostream>

    using namespace std;

    class Circle
        {
            public:

            Circle(double);
            void setRadius(double);
            double getRadius();
            void Display();
            double Diameter(double);
            double Circumference(double);
            double Area(double);

            private:

            double radius;

        };

        Circle::Circle(double radio)
            {
                setRadius(radio);
            }

        void    Circle::setRadius(double ra)
            {
                if (ra < 0)
                {
                    radius = 0;
                }
                else
                    radius = ra;
            }

        double  Circle::getRadius()
            {

                double rado;

            cout << "Enter the Radius:\n";
            cin >> rado;
            setRadius(rado);

            return radius;
            }

        do
Edit
Report

1 Answer

19

This line invokes a constructor with no arguments (known as default constructor):

Circle C;

The only constructor you have defined is:

Circle(double);

Hopefully this should point you in the right direction.

answered 2011-12-31T16:56:42.437

Your Answer