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:
Code:
int *i;
...
i = new int[23];
...
int nMembers = sizeof(i) / sizeof(int);
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:
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);
};
and I am trying to calculate the size of an array of these objects like so:
Code:
Card *m_card;
...
m_card = new Card[52];
...
int nMembers = sizeof(m_card) / sizeof(Card);
Can anyone see where I am going wrong? Or know a decent method?
Thanks in advance,
DT