Original Post
Hi guys, I'm having a weird problem. I'm keeping an array of pointers (base class type) and everything is fine until I add a member variable to the derived class, then I get unpredictable results (lock-ups), I really can't figure out what's going on, maybe it's the general design of my program ? Here is some code: class CEntity { int a; virtual void DoSomething()=0; }; class CRedEntity : publc CEntity { int x; // if I don't add this it's fine virtual void DoSomething(); }; Now some pointer arrays: // memory CEntity* pMemory=new CRedEntity[8]; // pointers CEntity** pRedPtrs=new CEntity*[8]; // set the pointers for(int i=0;i<8;i++) pRedPtrs=pMemory+i; // also tried =&pMemory // now I use the pointer array for everything, ex: CEntity* entity=pRedPtrs[0]; entity->DoSomething(); ... ... // actually, I create another master list of pointers for all the different colored entities: CEntity** pMasterList=new CEntity*[num_red+num_green]; // setup as first-in-last-out (ommited) // now I can loop through the whole list, regardless of entity color: for(int i=0;i; entity->DoSomething(); // or whatever ... } I really don't understand what I can be doing wrong, but as soon as I add something to the derived class it breaks. The reason I'm using the pointer arrays is for management of my entities. Does anybody see anything inherently wrong with this ? Thanks guys.