i have two classes namely Flight and Runway. Now i am trying to pass an array of these objects as parameter to a function.
void fun(Flight ptr1[],Runway ptr2[])
{
...
...
}
ptr1 should point to an array of Flight objects and ptr2 should point to an array of Runway objects.
Now inside this function fun() how do i access members of these classes. Also can i use ptr1++ or ptr2++ to move between the objects??
Also how would i be calling this func??something like this –
Flight array1[5];
Runway array2[2];
fun(array1,array2);
is interpreted as
This is called “decomposition,” and I think it’s rotten. It’s mainly a feature for backward compatibility with C. If you want pointers, specify pointers, not arrays, because pointers and arrays are different things.
You can also do
Now the parameters remain arrays inside the function, not pointers, so
++ arr1is illegal andsizeof arr1/sizeof arr1[0]is5. The argument arrays when you call the function also must be the correct size, exactly 5 and 7 respectively. In this context,&means pass-by-reference, so the arrays are not copied when you call the function.You can leverage the template system to generate a function for any size argument array, as well:
Such a template may be called with any-sized arrays, and NF and NR will be integral constants set to the proper sizes.