#include <iostream>
using namespace std;
class Circle
{
private:
double radius;
public:
Circle() //Constructor
{ radius = 0; }
Circle(double); //Parameterized Constructor
void setRadius(double);
double getRadius() const
{ return radius; }
double getArea() const
{ return 3.14 * radius * radius; }
};
Circle::Circle(double r)
{
radius = r;
}
void Circle::setRadius(double r)
{
radius = r;
}
int main()
{
int size = 3; //Set size of array of objects
Circle arr[size] = { Circle(1.2), Circle(2.2), Circle(5.5) }; //Array of Objects
for (int index = 0; index < size; index++)
{
cout << arr[index].Circle(); //Error: Invalid use of Circle::Circle
}
Circle b(2.8); //Instance of class
cout << b.getRadius(); //Prints out the radius of object
Circle c; //Another instance
cout << endl << c.getRadius(); //Another radius
double r; //Variable to store the radius based on user input
cout << "\nEnter a radius: ";
cin >> r;
c.setRadius(r); //Pass user input into radius member function
cout << c.getRadius(); //Print new radius of object c
cout << endl << c.getArea(); //Prints area of object c.
return 0;
}
I'm trying to figure out how to print out the values of the above array of objects using the class parmeterized constructor (it's supposed to print out the radius of each Circle object). When run the program, the error I get says invalid use of Circle::Circle.
cout << arr[index].Circle();tocout << arr[index].getRadius() << endl;