   Inheritances issues
  I have the following classesCObjectBase : public CRenderBaseCShapeBase : public CRenderBaseCRectangleBase : CShapeBase ( : public CRenderBase)I then have a vector<CObjectBase *>, but I want to put a CRectangleBase into it. Obviously this can not happen because CRectangle is not a CObjectBase. However, The both inherit CRenderBase. I do not want to make the vector a vector<CShapeBase *> because I have certain things in CObjectBase that I do not want to go into CObjectBase. Is there way I can make this happen?If it is completely not possible, can anyone think of a way that I could reset up my classes?   
  Why not have a separate vector of renderables. Whenever you add an object, you can add it to both lists. If you were to use smart pointers, this would simplify the memory management required for this.If you do this, why not go the whole way and make objects not inherit from renderable. After all, some games do feature "invisible" objects, to act as triggers or such. You can use composition instead, where an object could contain an optional renderable as a member.   ;  By composition do you mean the design pattern?Also, the CObjectBase containing a CRenderBase rather inheriting is a good idea (I some how forgot about triggers). That would basically have CObjectBase contain a CRenderBase pointer, correct?   ;Quote:By composition do you mean the design pattern?No, just plain old composition: member variables or fields.Quote:Also, the CObjectBase containing a CRenderBase rather inheriting is a good idea (I some how forgot about triggers). That would basically have CObjectBase contain a CRenderBase pointer, correct?Yes, a pointer, or smart pointer, or boost::optional, or even a container (if you want to attach renderables to an object, e.g. set an object on fire, the fire effect follows the object it is attached to). The container would simply be empty for a hidden object.   ;  I would have to look into smart pointers or a container as I do not know much about it. Do you know of any reading material (or possible code example) on the container you are talking about?   ;  A container is something like std::vector<>, std::list<> or std::deque, i.e. something that contains things.Smart pointers are something like boost::shared_ptr<>. The idea of a smart pointer is that they manage the memory for you, and delete the variable under certain conditions. For example, boost::shared_ptr allows you to make any number of copies of the pointer. Once the last pointer goes out of scope, the pointee is deleted automatically.Another possibility is something like what Zahlman proposes here, where you don't keep an explicit list of renderables but instead derive it while iterating over the objects. You could also have another renderable list, which is for renderables that aren't attached to an object. This would simplify the memory management, because each renderable is only owned by a single object at a time (its either attached to an entity, or the "free renderable" list, never both).   ;Quote:Original post by simotixBy composition do you mean the design pattern?Calling composition a design pattern is like putting on your resume that you know ASCII.Quote:That would basically have CObjectBase contain a CRenderBase pointer, correct?You need some kind of indirection because the contained thing needs to behave polymorphically. But make things easy for yourself: use some kind of smart pointer class.And take my 30-day challenge: take out the leading 'C's from your class names, and the trailing 'Base's from your base class names. Just name things "naturally", avoiding redundant information. If you aren't satisfied that it makes your code easier to read, and that the old names weren't actually helping you catch bugs (and it definitely can't help the compiler, anyway), I'll refund your money. :D   