Tutorial eg in C++

I have a question regarding the example covered in the section Classes (I) in the Tutorials of C++. Below is the example as given in the Tutorial and i have mentioned my doubt in the comment form in CAPITAL LETTERS:

/ member initialization
#include <iostream>
using namespace std;

class Circle {
double radius;
public:
Circle(double r) : radius(r) { }
double area() {return radius*radius*3.14159265;}
};

class Cylinder {
Circle base;
double height;
public:
Cylinder(double r, double h) : base (r), height(h) {} // HOW CAN r BE ASSIGNED TO base WHEN BOTH ARE OF DIFFERENT TYPES ie. base IS OF CLASS CYLINDER AND r IS OF TYPE DOUBLE
double volume() {return base.area() * height;}
};

int main () {
Cylinder foo (10,20);

cout << "foo's volume: " << foo.volume() << '\n';
return 0;
}

base is of type Circle. Circle has a single-parameter constructor that takes a double. Therefore, base (r) is legal.
HOW CAN r BE ASSIGNED TO base WHEN BOTH ARE OF DIFFERENT TYPES ie. base IS OF CLASS CYLINDER AND r IS OF TYPE DOUBLE
No, Cyclinder::base is of type Circle, which has a constructor that accepts a double as a parameter.
Topic archived. No new replies allowed.