カスタム型の動的配列で特に注意することはありますか?
ConditionParameter の動的配列を作成しようとしています (以下の定義)。
ConditionParameter* m_params;
...
m_params = new ConditionParameter[m_numParams];
しかし、上記の行の結果は、タイプ ConditionParameter の 1 つの新しいオブジェクトのみであり、そのアドレスは 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;
};