From b2f00007f5a9ad1ae3bddad6901e8e20d33a7e98 Mon Sep 17 00:00:00 2001 From: Krestol Denis Date: Tue, 9 Jun 2020 21:43:06 +0300 Subject: [PATCH] build fixes --- Lesson_9/SmartPointer/Car.h | 2 -- Lesson_9/SmartPointer/CarFactory.cpp | 2 +- Lesson_9/SmartPointer/CarFactory.h | 2 +- Lesson_9/SmartPointer/Driver.cpp | 7 ++++++- Lesson_9/SmartPointer/Driver.h | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Lesson_9/SmartPointer/Car.h b/Lesson_9/SmartPointer/Car.h index f3a904e..6a0162a 100644 --- a/Lesson_9/SmartPointer/Car.h +++ b/Lesson_9/SmartPointer/Car.h @@ -1,6 +1,4 @@ #pragma once - - class Car { public: diff --git a/Lesson_9/SmartPointer/CarFactory.cpp b/Lesson_9/SmartPointer/CarFactory.cpp index 8294990..1781918 100644 --- a/Lesson_9/SmartPointer/CarFactory.cpp +++ b/Lesson_9/SmartPointer/CarFactory.cpp @@ -4,5 +4,5 @@ std::unique_ptr CarFactory::BuildCar(const std::string& color) { - return std::make_unique(new Car(color)); + return std::make_unique(color); } diff --git a/Lesson_9/SmartPointer/CarFactory.h b/Lesson_9/SmartPointer/CarFactory.h index bf6a71a..41bb100 100644 --- a/Lesson_9/SmartPointer/CarFactory.h +++ b/Lesson_9/SmartPointer/CarFactory.h @@ -1,5 +1,5 @@ #pragma once -#include "Car.h" +class Car; class CarFactory { diff --git a/Lesson_9/SmartPointer/Driver.cpp b/Lesson_9/SmartPointer/Driver.cpp index bc9381a..298ec74 100644 --- a/Lesson_9/SmartPointer/Driver.cpp +++ b/Lesson_9/SmartPointer/Driver.cpp @@ -9,6 +9,11 @@ Driver::Driver(const std::string& name, std::shared_ptr factory) { } +Driver::~Driver() +{ + /*to avoid errors from incomplete type in unique_ptr*/ +} + void Driver::BuyCar(const std::string& color) { car_ = factory_->BuildCar(color); @@ -16,7 +21,7 @@ void Driver::BuyCar(const std::string& color) std::unique_ptr Driver::SellCar() { - return std::make_unique(car_.release()); + return std::unique_ptr(car_.release()); } void Driver::BuyUsedCar(Driver * d) diff --git a/Lesson_9/SmartPointer/Driver.h b/Lesson_9/SmartPointer/Driver.h index 469bde9..50dc702 100644 --- a/Lesson_9/SmartPointer/Driver.h +++ b/Lesson_9/SmartPointer/Driver.h @@ -1,11 +1,12 @@ #pragma once -#include "Car.h" +class Car; class CarFactory; class Driver { public: Driver(const std::string& name, std::shared_ptr factory); + ~Driver(); void BuyCar(const std::string& color);