Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lesson_9/SmartPointer/Car.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once


class Car
{
public:
Expand Down
2 changes: 1 addition & 1 deletion Lesson_9/SmartPointer/CarFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

std::unique_ptr<Car> CarFactory::BuildCar(const std::string& color)
{
return std::make_unique<Car>(new Car(color));
return std::make_unique<Car>(color);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ошибки здесь были

}
2 changes: 1 addition & 1 deletion Lesson_9/SmartPointer/CarFactory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "Car.h"
class Car;

class CarFactory
{
Expand Down
7 changes: 6 additions & 1 deletion Lesson_9/SmartPointer/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ Driver::Driver(const std::string& name, std::shared_ptr<CarFactory> factory)
{
}

Driver::~Driver()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если в unique_ptr тип, который объявлен предварительно, то требуется реализация деструктора, иначе компилятор генерирует деструктор и ему не "виден" полный тип Car
class Car;
std::unique_ptr car_;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вроде понятно, почему не работало, но не понятна логика этой ошибки.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если не прояснится после обсуженения процесса подключения файлов и компиляции - посмотрим отдельно

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошо

{
/*to avoid errors from incomplete type in unique_ptr*/
}

void Driver::BuyCar(const std::string& color)
{
car_ = factory_->BuildCar(color);
}

std::unique_ptr<Car> Driver::SellCar()
{
return std::make_unique<Car>(car_.release());
return std::unique_ptr<Car>(car_.release());
}

void Driver::BuyUsedCar(Driver * d)
Expand Down
3 changes: 2 additions & 1 deletion Lesson_9/SmartPointer/Driver.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once
#include "Car.h"
class Car;
class CarFactory;

class Driver
{
public:
Driver(const std::string& name, std::shared_ptr<CarFactory> factory);
~Driver();

void BuyCar(const std::string& color);

Expand Down