Классы стратегий
Код: Выделить всё
class Strategy
{
public:
virtual void doSomething() = 0;
};
class StrategyOne : public Strategy
{
public:
void doSomething(){};
};
class StrategyTwo : public Strategy
{
public:
void doSomething(){};
};
//Other strategies...
Model.h
Код: Выделить всё
class Model:
{
public:
Model(){};
//functions etc..
private:
std::unique_ptr _strategy;
};
Код: Выделить всё
void setStrategyAndDoSomething(std::string state)
{
if(state == "stateOne")
_strategy = std::make_unique();
else if(state == "stateTwo")
_strategy = std::make_unique();
_strategy->doSomething();
}
Во время компиляции я обнаружил следующее сообщение об ошибке:
Ошибка C2679, двоичная '=': не найден оператор, принимающий правый операнд типа 'std::unique_ptr' (или нет приемлемого преобразование)
Я попробовал поэкспериментировать с кодом, определив _strategy в самой функции void setStrategyAndDoSomething(std::string state), такой, что:
Код: Выделить всё
std::unique_ptr _strategy = std::make_unique();
Я что-то пропустил в абстрактных классах? (
Код: Выделить всё
Strategy
Подробнее здесь: https://stackoverflow.com/questions/790 ... rror-c2679