Reputation: 2975
This is my SimplePizzaFactory.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
My SimplePizzaFactory.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";
}
This is my 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
And this is my PizzaStore.cpp
#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();
}
When I am trying to compile my PizzaStore.cpp
I am getting below error:
$ 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){
All files are in the same folder, but still it is not able to find SimplePizzaFactory::Pizzatype type
though it is defined as public
.
I tried making it static
as well as extern
but no success.
What am I doing wrong?
Upvotes: 0
Views: 963
Reputation: 206667
This error is caused by a typo. Use
void orderPizza(SimplePizzaFactory::PizzaType type); // Uppercase 'T' in PizzaType.
instead of
void orderPizza(SimplePizzaFactory::Pizzatype type);
Upvotes: 4