自定义类型的动态数组有什么特别需要注意的吗?
我正在尝试创建一个 ConditionParameter 的动态数组(定义如下)
ConditionParameter* m_params;
...
m_params = new ConditionParameter[m_numParams];
但是上面一行的结果只是一个ConditionParameter类型的新对象,其地址存储在m_params中。
struct ConditionParameter
{
ConditionParameter() :
type(OBJ_TYPE_OBJECT),
semantic(OP_SEMANTIC_TYPE_NONE),
instance(NULL),
attrib(ATTRIB_TYPE_NONE),
value(0)
{}
ConditionParameter(const ConditionParameter& other)
{
attrib = other.attrib;
instance = other.instance;
semantic = other.semantic;
type = other.type;
value = other.value;
}
ConditionParameter& operator = (ConditionParameter& other)
{
attrib = other.attrib;
instance = other.instance;
semantic = other.semantic;
type = other.type;
value = other.value;
return *this;
}
ObjectType type;
OperandSemanticType semantic;
Object* instance;
AttributeType attrib;
int value;
};