0

Could someone please make me understand a line in the code?
Ive commented it

class Circle {
	protected:
  		double radius;
	public:
  		Circle(double r = 1.0) : radius(r) {} //this part is what i dont understand
  		double calVal();
};
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Roses89
1

That line is the constructor. It says to use a default value of 1.0 if nothing is passed. If something is passed, the : radius(r) sets the member variable 'radius' to the value of 'r'. This is called an 'initializer list'.

Dave

Votes + Comments
Yep. :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.