world.cpp
来自「《c++ 实践之路》光盘中的源代码」· C++ 代码 · 共 47 行
CPP
47 行
// (c) Bartosz Milewski, 2000
#include <iostream>
class CelestialBody
{
public:
CelestialBody (double mass)
: _mass (mass)
{
std::cout << "Creating celestial body of mass "
<< _mass << "\n";
}
~CelestialBody ()
{
std::cout << "Destroying celestial body of mass "
<< _mass << "\n";
}
private:
const double _mass;
};
class Star: public CelestialBody // Star is a CelestialBody
{
public:
Star (double mass, double brightness)
: CelestialBody (mass),
_brightness (brightness)
{
std::cout << "Creating a star of brightness "
<< _brightness << "\n";
}
~Star ()
{
std::cout << "Destroying a star of brightness "
<< _brightness << "\n";
}
private:
const double _brightness;
};
int main ()
{
std::cout << " Entering main.\n";
Star aStar ( 1234.5, 0.1 );
std::cout << " Exiting main.\n";
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?