J
jlea
Does anyone know how to pass a managed array to a method and have that
method actually create the array if necessary, ie., if the passed array is
null? For example:
void AddAttribute(XmlAttribute* attribList[], XmlAttribute* anAttrib)
{
if (attribList == 0L) {
attribList = new XmlAttribute * [1];
attribList[0] = anAttrib;
} else {
if (!AttributeExists(attribList, anAttrib)) {
int size = attribList->get_Length();
for (int i=1; i<=size; i++) {
if (attribList[i-1] == 0L) {
attribList[i-1] = anAttrib;
goto Done;
}
}
XmlAttribute* temp[];
temp = new XmlAttribute * [size+1];
attribList->CopyTo(temp, 0);
temp[size] = anAttrib;
attribList = temp;
} else {
throw new ApplicationException("Attribute already exsits");
}
}
Done: ;
}
In the old days of native C++, I would have passed the array as:
XmlAttribute*& attribList so that the function can change the pointer
itself. Thanks. Jon.
method actually create the array if necessary, ie., if the passed array is
null? For example:
void AddAttribute(XmlAttribute* attribList[], XmlAttribute* anAttrib)
{
if (attribList == 0L) {
attribList = new XmlAttribute * [1];
attribList[0] = anAttrib;
} else {
if (!AttributeExists(attribList, anAttrib)) {
int size = attribList->get_Length();
for (int i=1; i<=size; i++) {
if (attribList[i-1] == 0L) {
attribList[i-1] = anAttrib;
goto Done;
}
}
XmlAttribute* temp[];
temp = new XmlAttribute * [size+1];
attribList->CopyTo(temp, 0);
temp[size] = anAttrib;
attribList = temp;
} else {
throw new ApplicationException("Attribute already exsits");
}
}
Done: ;
}
In the old days of native C++, I would have passed the array as:
XmlAttribute*& attribList so that the function can change the pointer
itself. Thanks. Jon.