在类中声明动态结构和无符号字符数组的正确方法是什么?
#define GENDER_MALE 0
#define GENDER_FEMALE 1
class c_House {
public:
c_House();
c_House( unsigned int in_BedRoomCount,
short in_FloorCount,
const char* in_Address,
unsigned int in_PeopleCount ) :
BedRoomCount( in_BedRoomCount ),
FloorCount( in_FloorCount ),
Address( in_Address ),
PeopleCount( in_PeopleCount )
{
this->Array = new unsigned char[ in_BedRoomCount ];
this->People = new PEOPLE[ in_PeopleCount ];
};
~c_House() { delete[] this->Array; };
// PROPERTIES
private:
struct PERSON {
unsigned short Age;
const char* Name;
unsigned short Gender;
};
unsigned int BedRoomCount;
short FloorCount;
const char* Address;
unsigned char* Array;
unsigned int PeopleCount;
PERSON *People;
// ACTIONS
private:
void OpenGarage( bool in_Open );
void Vacuum();
};
我应该如何声明一个动态数组(int 和 struct)?我知道这会很危险——想想深拷贝等等:
this->Array = new unsigned char[ in_BedRoomCount ];
this->People = new PEOPLE[ in_PeopleCount ];
这是删除 int 数组的正确方法吗?
~c_House() { delete[] this->Array; };
结构数组呢?