I am trying to write a function that takes in a variable number of parameters. My research has directed me to learn about va_list and its methods (va_start, va_end, va_arg). The issue is that the parameters that I am passing into this function are references to objects created outside the function.
myClass obj1, obj2, obj3;
modifyObjects(3, obj1, 55, obj2, 33, obj, 35)
Here is the implementation I tried:
void modifyObjects(int numObjects, ...)
{
va_list;
va_start(list, numObjects);
int i;
for(i=0;i<numObjects;++i)
{
myClass* tempObjectHandle = va_arg(list, &myClass ); //get the reference to the object (THIS DOES NOT WORK!)
int size = va_arg(list, int); //get the size
tempObjectHandle->set(size); //tempObjectHandle should be pointing to object defined outside the function to set its size
}
va_end(list);
}
Is there any way to create objects and pass a variable list of references to those objects into a function so that once the function returns, all objects have been modified?
ADDITIONAL INFO:
I am also limited by to the C++03 standard that that is what is supported by the ARM compiler.
Thanks!