Romasmi / cpp-practice

0 stars 0 forks source link

Замечания по объёмным телам #19

Open alexey-malov opened 5 years ago

alexey-malov commented 5 years ago

https://docs.microsoft.com/en-us/cpp/build/creating-precompiled-header-files?view=vs-2019

alexey-malov commented 5 years ago
class CSolidBody : public CBody
{
public:
    CSolidBody(const std::string& type, double density);

    double GetDensity() const override;
    virtual double GetVolume() const = 0;
alexey-malov commented 5 years ago
double CCompound::GetDensity() const
{
    return GetMass() / GetDensity();
}
alexey-malov commented 5 years ago
double CCompound::GetVolume() const
{
    double volume = 0;
    for (shared_ptr<CBody> body : m_children)
    {
        volume += body->GetMass();
    }
    return volume;
}
alexey-malov commented 5 years ago
bool CCompound::AddChildBody(shared_ptr<CBody> child)
{
    /*if (make_shared<CBody>(this) == child)
    {
        return false;
    }*/

    try
    {
        m_children.push_back(child);
    }
    catch (const exception& e)
    {
        std::cout << e.what() << '\n';
        return false;
    }
    return true;
}
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago