0

I'm having trouble initializing the fields of a class object member variable through a class constructor. This is part of the code that creates a Circle Object: enter image description here

And here's the class definition for the Circle and Point classes: enter image description here

enter image description here

Is this the appropriate way of writing the constructor for the Circle function? If so, what's the correct way of initializing the x and y fields for the center_ member variable? Would it be something like this:

 Circle::Circle(Point(int x, int y), double n)
 {
     radius_ = n;
     center_{x, y}; 
 }
3
  • What does your C++ textbook have to say on the subject?
    – user2100815
    Nov 27, 2017 at 0:34
  • No, it should be Circle::Circle(Point p, double n). And please reread the class chapter in your C++ book.
    – Bo Persson
    Nov 27, 2017 at 0:34
  • This is such a basic question, it'll help you in the long run to work through the fundamentals of the language using a text book. Here's a starting point: stackoverflow.com/questions/388242/…
    – R Sahu
    Nov 27, 2017 at 0:36

1 Answer 1

0

A few error free constructors for the circle class would be the following:

Circle::Circle(Point x, double n);
Circle::Circle(int x, int y, double n); // Then create the point in the constructor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.