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}; 
 }
JURO312
  • 69
  • 5
  • What does your C++ textbook have to say on the subject? –  Nov 27 '17 at 00: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 '17 at 00: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: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – R Sahu Nov 27 '17 at 00:36

1 Answers1

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
Jake Freeman
  • 1,700
  • 1
  • 8
  • 15