I am currently blocked trying to create a a random subclass object from a parent class. I get the error :
main.obj : error LNK2005: "class Shape * (__cdecl** creat)(struct vec4)" (?creat@@3PAP6APAVShape@@U?$tvec4@M@detail@glm@@@ZA) already defined in **.obj
All I am trying to do is make the call Shape obj = Create(vec4()); return randomly a Box, Cylinder or Sphere object.
Here is my code a little bit striped down.
For reference, I am trying to implement this idea.
class Shape : public Node {
public:
virtual ~Shape();
};
class Box : public Shape {
public:
Box(vec4 color);
};
class Cylinder : public Shape {
public:
Cylinder(vec4 color);
};
class Sphere : public Shape {
public:
Sphere(vec4 color);
};
template<typename T>
Shape* Create(vec4 color) { return new T(color); }
typedef Shape* (*CreateF)(vec4);
CreateF creat[] = { &Create<Box>, &Create<Cylinder>, &Create <Sphere> };
const size_t fcount = sizeof(creat) / sizeof(*creat);
Shape *Create(vec4 color){ return creat[rand() % fcount](color); }
Can anybody explain/solve what I am doing wrong?
Aucun commentaire:
Enregistrer un commentaire