class Obj3D
{
public:
std::string id;
explicit Obj3D(const std::string& name)
{
id = name;
}
virtual ~Obj3D(){}
virtual void Draw(void) = 0;
};
class Mesh : public Obj3D
{
public:
explicit Mesh(const std::string& name) : Obj3D(name){}
virtual ~Mesh(){}
virtual void Draw(void)
{
std::cout << id << std::endl;
}
};
class Cube : public Obj3D
{
public:
explicit Cube(const std::string& name) : Obj3D(name){}
virtual ~Cube(){}
virtual void Draw(void)
{
std::cout << id << std::endl;
}
};
class Sphere : public Obj3D
{
public:
explicit Sphere(const std::string& name) : Obj3D(name){}
virtual ~Sphere(){}
virtual void Draw(void)
{
std::cout << id << std::endl;
}
};
Now I want to make one array that holds all various derived objects....
//now place each object into array? I can't see how you can allocate these after you already allocated 1000 for Obj3D* pointers...
Obj3D* p = new Obj3D[1000];[/font]// I am sure this isn't going to work....
for(int i = 0; i < 1000; ++i)
p = new Mesh();//or cube, sphere... or worse yet add one at a time...
So with a std::vector I can do this...
std::vector<Obj3D*> objects;
objects.push_back(new Mesh("BLAH"));
objects.push_back(new Sphere("BLAH"));
objects.push_back(new Cube("BLAH"));
then run through the vector and walla...
Thanks....