double cirArea[numCircle]; is an array of double . It should be an array of Circle . However, numCircle is non-constant, so you cannot do this (even if the compiler allows it. It is not independent). You should use a dynamically allocated array or even better std::vector .
A complete solution in C ++ would be:
int main(){ Circle *area; double cirRadius; int numCircle; cout << "How many circles?" << endl; cin >> numCircle; std::vector<Circle> cirArea; cirArea.reserve(numCircle); for (int i = 0; i < numCircle; i++){ cout << "Enter the radius: "; cin >> cirRadius; cirArea.emplace_back(); cirArea.back().setRadius(cirRadius); } }
If Circle accept Radius as a constructor argument , you can replace these two lines:
cirArea.emplace_back(); cirArea.back().setRadius(cirRadius);
with:
cirArea.emplace_back(cirRadius);
source share