我用谷歌搜索了这条错误消息,但找不到与我的案例的关系。
我试着做一个cars abstract factory
:
#include <iostream>
using namespace std;
class IFactory
{
public:
enum FACTORIES { MERCEDES, AUDI, SKODA };
virtual const char* getCar() = 0;
static IFactory* createFactory(FACTORIES factory)
{
if(factory == MERCEDES)
return new MercedesFactory;
if(factory == AUDI)
return new AudiFactory;
else
return new SkodaFactory;
}
};
class AudiFactory : public IFactory
{
public:
const char* getCar()
{
return "Audi";
}
};
class MercedesFactory : public IFactory
{
public:
const char* getCar()
{
return "EClass";
}
};
class SkodaFactory : public IFactory
{
public:
const char* getCar()
{
return "Octavia";
}
};
我有 3 个错误:
error C2061: syntax error : identifier 'MercedesFactory'
error C2061: syntax error : identifier 'AudiFactory'
error C2061: syntax error : identifier 'SkodaFactory'
线上:
return new MercedesFactory
return new AudiFactory
return new SkodaFactory
(每行中的每个错误)。
你能帮我找出问题吗?提前致谢。