c++官方文档-class

#include <iostream>
using namespace std;

class Circle
{
    double radius;
public:
    Circle(double r)
    {
        radius = r;
    }
    double area()
    {
        return 2 * radius;
    }
};
class Cylinder
{
    Circle base;
    double height;
public:
    Cylinder(double r, double h)
            : base(r), height(h)
    {
    }
    double volume()
    {
        return base.area() * height;
    }
};
//uniform initializer
//Cylinder::Cylinder(double r, double h)
//        : base { r }, height { h }
//{
//}
class Rectangle
{
    int width, height;
public:
    Rectangle();
    Rectangle(int, int);
    void set_values(int, int);
    int area(void)
    {
        return width * height;
    }
    ;
};
Rectangle::Rectangle()
{
    width = 5;
    height = 5;
}
Rectangle::Rectangle(int x, int y)
        : width(x), height(y)
{
}

//Rectangle::Rectangle(int a, int b)
//{
//    width = a;
//    height = b;
//}
void Rectangle::set_values(int x, int y)
{
    width = x;
    height = y;
}

int main()
{
    Rectangle rect(3, 4);
    int myarea = rect.area();
    cout << myarea << endl;
//    Circle foo(10.0);   // functional form
    Circle bar = 20.0;   // assignment init.
    Circle baz { 30.0 };   // uniform init.
    Circle qux = { 40.0 }; // POD-like
//    cout << foo.area() << endl;
    cout << bar.area() << endl;
    cout << baz.area() << endl;
    cout << qux.area() << endl;
    Rectangle rectb;   // default constructor called
    Rectangle rectc(); // function declaration (default constructor NOT called)
    Rectangle rectd { }; // default constructor called

    Cylinder foo(10, 20);
    cout << "foo's volume: " << foo.volume() << '
';
    Rectangle* foop;
    foop = &rect;
    cout << foop->area() << endl;
    delete foop;
    return 0;
}