我正在学习一些设计模式。我坚持使用继承的Singleton,这是我的代码:
#ifndef FACTORY_CPP
#define FACTORY_CPP
#include "Istogramma.cpp"
class Factory
{
protected:
Factory(){}
static Factory * istance;
public:
static Factory* getIstance(){
return istance;
}
virtual Istogramma* creaIstogramma()=0;
};
#endif
这是我的单身基类。 现在是子类:
class FactoryConAB : public Factory
{
protected:
FactoryConAB(){}
public:
static void Istance()
{
if(istance == 0){
istance = new FactoryConAB;
}
}
virtual Istogramma* creaIstogramma(){
return new IstogrammaConAB;
}
};
#endif
现在主要:
#include <iostream>
#include "applicazione.cpp"
#include "FactoryConCancelletto.cpp"
#include "FactoryConAB.cpp"
using namespace std;
int main ()
{
FactoryConAB::Istance();
Applicazione singleton;
singleton.disegna(30);
return 0 ;
}
当我编译时,我收到此错误:
g++ -o "SingletonFactory" ./Factory.o ./FactoryConAB.o ./FactoryConCancelletto.o ./Istogramma.o ./IstogrammaConAB.o ./IstogrammaConCancelletto.o ./applicazione.o ./main.o
./main.o: In function `FactoryConAB::Istance()':
/home/haze/workspace/SingletonFactory/Debug/../FactoryConAB.cpp:14: undefined reference to `Factory::istance'
makefile:44: recipe for target 'SingletonFactory' failed
/home/haze/workspace/SingletonFactory/Debug/../FactoryConAB.cpp:15: undefined reference to `Factory::istance'
collect2: error: ld returned 1 exit status
make: *** [SingletonFactory] Error 1
有人可以解释为什么我会收到这个错误吗?如果有人链接到模式并希望分享我真的很感激!