I'm trying to calculate how many members my dynamically allocated object array has and am having difficulty!
If I was to do it with an array of, say, integers, I would do it like this:
This does not work with my class object though. Instead, sizeof(MyObject) returns 4 bytes, the size of the pointer itself. My object is defined like this:Code:int *i; ... i = new int[23]; ... int nMembers = sizeof(i) / sizeof(int);
and I am trying to calculate the size of an array of these objects like so:Code:class Card { int m_pip; SUIT m_suit; // SUIT is an enumerated type public: BOOL m_error; Card(int pip = 0, SUIT suit = NO_SUIT); ~Card(void) {m_pip = 0; m_suit = NO_SUIT;} int GetPip(void){return(m_pip);} SUIT GetSuit(void){return(m_suit);} int SetCard(int pip, SUIT suit); int GetIndex(void); void GetText(char *txt); void GetShortText(char *txt); };
Can anyone see where I am going wrong? Or know a decent method?Code:Card *m_card; ... m_card = new Card[52]; ... int nMembers = sizeof(m_card) / sizeof(Card);
Thanks in advance,
DT



LinkBack URL
About LinkBacks



There's lots of different containers like vectors that can be used for dynamic alloc. To name the ones I know, in order of importance: