小编Moc*_*ird的帖子

出现unique_ptr问题:不是“ std”的成员

我很难找到为什么编译器会告诉我这一点:

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)
Run Code Online (Sandbox Code Playgroud)

和这个:

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

我有unique_ptr的包含

#include <memory>
Run Code Online (Sandbox Code Playgroud)

并且我使用了良好的C ++编译标志

CFLAGS  =   -std=c++11 -W -Wall -Wextra -Werror -pedantic
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用命名空间std ;

这是我使用std :: unique_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 …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

3
推荐指数
2
解决办法
9394
查看次数

标签 统计

c++ ×1

c++11 ×1