Advertisement

C++ classes, new and arrays

Started by March 06, 2000 12:01 AM
1 comment, last by BigCarlito 24 years, 7 months ago
I can''t figure this one out: I have a class for my character animation, say CCharacter, that has a CSkeleton ptr. That gets newed and in the CSkeleton object, I dynamically allocate an array of CBones with new kinda like: class CCharacter { protected: CSkeleton* m_pSkeleton; public: CCharacter() { m_pSkeleton = new CSkeleton( somefile ); } }; class CSkeleton { protected: CBone* m_pBones; public: CSkeleton(char* filename) { m_pBones = new CBone[NumBones]; } }; This works fine in Debug build, but crashes on allocating the CBones in Release build. I guess the question is, is this bad programming to new member variables like that? If I hardcode the number of bones and use a member variable like: CBone m_pBones[17]; Then I don''t get the error, but that stinks! It almost seems like it''s trying to allocate the CBone array from the memory allocated for the CSkeleton, or maybe right after it or something, I don''t know. So I guess the second question is how would you go about finding out what is causing the exception? Is there any way? I know I have enough memory. Thanks in advance for any help!
I could very well be wrong, but maybe you should allocate your bones on the free store, and THEN input your bones data file into that allocated memory. Please yell at me if I''m wrong.
Advertisement
I should probably know this, but how would you allocate an array of objects from an already allocated block of memory? Also, anyone else have any clues about my question? Thanks!

This topic is closed to new replies.

Advertisement