quote:Original post by shrooboo
All of the objects in my game will be of the type OBJECT. So, lets say a character in the game has a gun. He fires a bullet. I will need to dynamically create a new bullet object.
Object *obj = new Bullet;
quote:
I need to be able to run through each object and check for collision detection and the like.
Then the design that you've described is completely inadequate. The problem is that you are asking about things that are rather basic, which you can learn in any decent introductory C++ text. Which are you using?
quote:
Is that any clearer?
It sounds like you are going to have a base class called "Object" and everything in your game derives from that. Despite the fact that design is something of a cop-out in C++, I suggest you learn a little about inheritance and polymorphism. To get you started, you might want to study this code:
#include <vector>#include <algorithm>#include <functional>#include <iostream>class base{public: virtual void foo() = 0; virtual ~base() {}};class derived1 : public base{public: void foo() { std::cout << "derived1::foo()\n"; }};class derived2 : public base{public: void foo() { std::cout << "derived2::foo()\n"; }};void Delete(base* b){ delete b;}int main(){ std::vector<base*> v; v.push_back(new derived1); v.push_back(new derived2); v.push_back(new derived2); v.push_back(new derived1); v.push_back(new derived1); std::for_each(v.begin(), v.end(), std::mem_fun(&base::foo)); std::for_each(v.begin(), v.end(), Delete);}
[edited by - SabreMan on November 6, 2002 6:28:12 PM]