Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从另一个文件访问类的公共枚举:C++;_C++_Enums - Fatal编程技术网

C++ 如何从另一个文件访问类的公共枚举:C++;

C++ 如何从另一个文件访问类的公共枚举:C++;,c++,enums,C++,Enums,这是我的simplepizza工厂.h #pragma once #ifndef SIMPLE_PIZZA_FACTORY_H #define SIMPLE_PIZZA_FACTORY_H #include <iostream> #include <string> #include "Pizza.h" #include "cheesePizza.h" #include "veggiePizza.h" using namespace std; class SimpleP

这是我的
simplepizza工厂.h

#pragma once
#ifndef SIMPLE_PIZZA_FACTORY_H
#define SIMPLE_PIZZA_FACTORY_H
#include <iostream>
#include <string>
#include "Pizza.h"
#include "cheesePizza.h"
#include "veggiePizza.h"

using namespace std;

class SimplePizzaFactory{
public:
enum PizzaType {
         cheese,
         veggie
         };
Pizza* createPizza(PizzaType type);
    };

#endif
这是我的
PizzaStore.h

#pragma once
#ifndef PIZZA_STORE_H
#define PIZZA_STORE_H
#include "SimplePizzaFactory.h"

class PizzaStore{
SimplePizzaFactory* factory;
public:
PizzaStore(SimplePizzaFactory* factory);
void orderPizza(SimplePizzaFactory::Pizzatype type);
    };

#endif
这是我的
PizzaStore.cpp

#include "SimplePizzaFactory.h"

Pizza* SimplePizzaFactory::createPizza(PizzaType type)
{
    switch(type){
        case cheese:
                       return new cheesePizza();

        case veggie:
                       return new veggiePizza();
        }
        throw "Invalid Pizza Type";
    }
#include "PizzaStore.h"

using namespace std;

PizzaStore::PizzaStore(SimplePizzaFactory* factory){
    this->factory=factory;
    }


void PizzaStore::orderPizza(SimplePizzaFactory::Pizzatype type){
    Pizza* pizza=factory.createPizza(type);
    Pizza->prepare();
    Pizza->bake();
    Pizza->cut();
    Pizza->box();
    }
当我试图编译我的
PizzaStore.cpp
时,出现以下错误:

$ g++ -Wall -c PizzaStore.cpp -o PizzaStore.o
In file included from PizzaStore.cpp:1:0:
PizzaStore.h:10:37: error: ‘SimplePizzaFactory::Pizzatype’ has not been declared
 void orderPizza(SimplePizzaFactory::Pizzatype type);
                                     ^
PizzaStore.cpp:12:49: error: variable or field ‘orderPizza’ declared void
 void PizzaStore::orderPizza(SimplePizzaFactory::Pizzatype type){
                                                 ^
PizzaStore.cpp:12:29: error: ‘Pizzatype’ is not a member of ‘SimplePizzaFactory’
 void PizzaStore::orderPizza(SimplePizzaFactory::Pizzatype type){
所有文件都在同一个文件夹中,但它仍然无法找到
SimplePizzaFactory::Pizzatype类型
,尽管它被定义为
public

我试着使它成为
静态的
以及
外部的
,但没有成功


我做错了什么?

这个错误是由打字错误引起的。使用

void orderPizza(SimplePizzaFactory::PizzaType type); // Uppercase 'T' in PizzaType.
而不是

void orderPizza(SimplePizzaFactory::Pizzatype type);

此错误是由输入错误引起的。使用

void orderPizza(SimplePizzaFactory::PizzaType type); // Uppercase 'T' in PizzaType.
而不是

void orderPizza(SimplePizzaFactory::Pizzatype type);