LikhachevAV / OOP2016

0 stars 0 forks source link

Замечания по Shapes #7

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
    //double GetArea() const override = 0;
    //double GetPerimeter() const override = 0;
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
#include "IShape.h"
#include "Circle.h"

void DoSomething(const IShape & shape)
{
    (void)&shape;
}

int main()
{
    CCircle circle({100, 100}, 100, "red", "green");
    DoSomething(circle);
    return 0;
}
alexey-malov commented 7 years ago
1>c1xx : fatal error C1083: Cannot open source file: 'ShapesFactory.cpp': No such file or directory
alexey-malov commented 7 years ago
            CCircle c1(CPoint(0, 0), 0, "", "");
            auto sp = make_shared<CCircle>(CPoint(0, 0), 0, "", "");
            shared_ptr<CCircle> sp2(new CCircle(CPoint(0, 0), 0, "", ""));

            auto sp1 = make_shared<CCircle>(c1); // копия c1
            shared_ptr<CCircle> sp2(new CCircle(c1)); // копия c1

вот так в куче можно создать объект

alexey-malov commented 7 years ago
        switch (typeIt->second) {
        case ShapeTypeEnum::circle:
            try{
                auto sp = make_shared<CCircle>(CPoint(0, 0), 0, "", "");
                strm >> *sp;
                shapesVector.push_back(sp);
            }
            catch (std::exception e)
            {
                cout << e.what() << endl;
            }
            break;
        case ShapeTypeEnum::rectangle:
            try {
                auto sp = make_shared<CRectangle>(CPoint(0, 0), CPoint(0, 0), "", "");
                strm >> *sp;
                shapesVector.push_back(sp);
            }
            catch (std::exception e)
            {
                cout << e.what() << endl;
            }
            break;
        case ShapeTypeEnum::triangle:
            try {
                auto sp = make_shared<CTriangle>(CPoint(0, 0),
                    CPoint(0, 0), CPoint(0, 0), "", "");
                strm >> *sp;
                shapesVector.push_back(sp);
            }
            catch (std::exception e)
            {
                cout << e.what() << endl;
            }
            break;
        }
alexey-malov commented 7 years ago
    auto less_area = [&](shared_ptr<IShape> const& sh1, shared_ptr<IShape> const& sh2) {
        return sh1->GetArea() < sh2->GetArea();
    };
auto lessArea = [](auto & sh1, auto & sh2){
    return sh1->GetArea() < sh2->GetArea();
};