Hi,
I tried to do a basic hopefully almost correct factory where its simply just return new "insert class here".
Here the class I want to dublicate/create with my factory
class Enity
{
public:
Enity(){};
std::vector<BaseComponent> ComponentList;
template<class ComponentType>
void AddComponent(ComponentType type);
void Destroy();
};
Here the factory class, which Sit in a header btw
class BasicFactory
{
public:
BasicFactory(){}
virtual ~BasicFactory(){}
template<class EnityType>
EnityType* InstantiateEnity(EnityType type);
};
class EnityFactory : public BasicFactory
{
public:
EnityFactory(){}
virtual ~EnityFactory(){}
template<class EnityType>
Enity* InstantiateEnity(EnityType type);
};
And here I declared the function to the factory
template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
return new type;
}
Seems like even a Idiot guide is to advance for me :(
http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part-1
and here's the tutorial I kinda followed
Here what I tried to do
Enity TestComp;
std::vector<Enity> vEnity;
std::vector<Enity>::iterator vEnityEnd;
int vEnityMax = 10;
EnityFactory eFactory;
int vEnitySize = 0;
void Update()
{
vEnitySize = vEnity.size();
vEnityEnd = vEnity.end();
if(vEnitySize < vEnityMax)
{
//MessageBox(0,"Lets hope this work","Enity have NOT Increased by 1 yet!",MB_OK);
TestComp = &eFactory.InstantiateEnity(Enity); <- error of illegal use of this type as an expression
vEnity.insert(vEnityEnd,TestComp);
MessageBox(0,"Screw This","Enity Increased by 1!",MB_OK);
}
Test.Update(pWCamera);
TestB.Update(pWCamera);
}