lundi 17 avril 2017

Trouble with uniqu_ptr : not a member of 'std'

I have a hard time finding why compiler tell me this:

main.cpp:51:17: error: ‘unique_ptr’ in namespace ‘std’ does not name a template type
 static std::unique_ptr<Pizza> createPizza(PizzaType t_pizza)

and this:

main.cpp:69:5: error: ‘unique_ptr’ is not a member of ‘std’
 std::unique_ptr<Pizza> pizza = PizzaFactory::createPizza(t_pizzaType);

I have the include for uniqu_ptr and I use the good compilation flags liek that:

#include <memory>

CFLAGS  =   -std=c++11 -W -Wall -Wextra -Werror -pedantic

I have already try using namespace std;

Here are the block of code where I use std::uniqu_ptr

class PizzaFactory
{
 public:
  enum PizzaType
  {
  Hawaiian,
  Vegetarian,
  Carnivoro
  };

  static std::unique_ptr<Pizza> createPizza(PizzaType t_pizza)
  {
  switch (t_pizza)
  {
  case Hawaiian:
    return std::unique_ptr<HawaiianPizza>(new HawaiianPizza());
  case Vegetarian:
    return std::unique_ptr<VegetarianPizza>(new VegetarianPizza());
  case Carnivoro:
    return std::unique_ptr<CarnivoroPizza>(new CarnivoroPizza());
  default:
    throw "Invalid pizza type.";
  }
  }
};

void pizza_information(PizzaFactory::PizzaType t_pizzaType)
{
  std::unique_ptr<Pizza> pizza = PizzaFactory::createPizza(t_pizzaType);
  std::cout << "Price of " << t_pizzaType << "is " << pizza->getPrice() << '\n';
}

I really can find what's wrong with this code, please help

Thank you.

Aucun commentaire:

Enregistrer un commentaire