   Question About ScreenObjects
  Okay, so this class defines a Cross Object, a Cross is a Mobile, is an Object..#ifndef C_CROSS_H#define C_CROSS_H#include "Mobiles.h"class Cross : public Mobiles{public:MS3DModel *Model1; // pointer to the model all cross instances use};#endifWhat happens if we want more than one Cross Object on the screen at the same time? I don't want to have to hard code another instance of the cross object, how can I make it so the user can create an instance of this object, (say we have a peasant object that has a build function, that can click build->cross, we place another cross on the screen, at a given location)Is this what template classes are used for? I'm sure someone here can enlighten me   
  Hmm... Well, the thing you posted there is called a class declaration. It doesn't actually create a Cross object, it's just a blueprint of what a cross object is.To actually create a cross object, you can do like this:Cross a, b, c, d;a.DoSomething();b.DoSomething();...I'm not sure if I'm misunderstanding your post because this seems really basic, but anyway hope that helps.   ;  Oh Oh, I know how to create a Class objectCross Cross1, Cross2, etc , etc;But the thing is, I don't know when I'm going to need a cross object and when I'm not, and I can't have just a single instance of the Cross object if I want Multiple Crosses on the screen...  I don't want to have to hardcode 50 cross object instances when I only need one, yknow?I want the user to be able to decide when we need a new cross object instance..ex.  objWorker.build(Cross) :  This would throw a new cross object to the renderer and draw it.   ;  std::vector< Object*> scene_items;scene_items.push_back( new Cross );or whatever...It sounds like you need to learn C++. I *strongly* recommend the book Accelerated C++ by Koenig and Moo over any other.;  Lol that response makes me sad, I've been working with C++ for over a year now.  I still don't think you two are understanding my problem...I KNOW HOW TO CREATE OBJECT INSTANCES!!!I DON'T WANT TO HAVE TO HARDCODE 50 CROSS OBJECTS WHEN THE WORLD ONLY NEEDS 1, MAYBE 2, MAYBE 20, WHO KNOWS!Wait wait,scene_items.push_back( new Cross );Putting new cross in there creates a new instance of cross in the vector?  That's exactly what I wanted, thanks..I thought the only way to do it was to create a cross object, and then pushback into the vector, not do it all in one nifty step that I can put if statements around, sweet.   ;Quote:Original post by ShaminoOh Oh, I know how to create a Class objectWhen you create a new object, you either allocate statically (on the stack) or dynamically (on the heap). In terms of C++, you're doing static allocations when you use a normal variable definition. When you use the new operator, you're dynamically allocating a variable on the stack.// Static allocationCross myCross;// Dynamic allocationMobiles* myCross = new Cross();Allocating variables on the stack is faster, but it's limiting since you need to know in advance how many variables you're going to be allocating memory for.To solve your particular problem, one way around this limitation is to use an array. Make an array that can contain the maximum number of objects of a particular type that you'll need and fill it with "blanks" - objects that contain junk data or otherwise indicate that they're meaningless. When you want the user to add a new object to the list, fill out another element with "good" data. Then you can just iterate through the array and perform whatever actions you need to on each object.An arguably better solution would be to dynamically allocate your objects. I'd suggest reading up on pointers and the new operator if you aren't already familiar with them. If you want a dynamically allocated array (one that automatically grows as it needs to, so you're not limited by the array size), use std::vector.Quote:Putting new cross in there creates a new instance of cross in the vector? That's exactly what I wanted, thanks..Yes, but it dynamically allocates memory for it, so you'll need to make a vector of either Mobiles* or Cross* if you want to use new. You'll also need to clean up the memory by iterating through the vector and deleteing the memory each pointer points to.   ;  Wow....Just... wow.You ... frighten me.;  Right right...I just wasn't aware I could pull off a new operator in the vector gates<---- absent minded programmerI think I want a vector of Object* (thats one that cross inherits but you don't see in the code there)  then just create a single vector scene_objects to hold information for everything that needs to be added to the renderer..Then the nifty draw function of the renderer draws everything in the scene_objects vector, sweet...Object oriented render engine here I come :D   