Array of Objects

Array of Objects

I have two questions. How do I pass an array of objects as an argument? How do I fix an error like “do or while loops are not expanded inline”?

To answer your first question: you can either pass a vector of objects by reference, or a pointer to the array:

 void func( vector & vf);int func2(){  vector  vf;  func(vf);//pass vector of Foo's}

Passing an array is even simpler:

 void func( Foo* farr);int func2(){ Foo f[10]; func(f);//pass array of Foo's}

As for your second question: your compiler tries to convince you to get rid of the inline specifier. Most compilers refuse to inline complex functions (e.g., functions with loops and do-while blocks). If your function is defined inside the class body, move its definition outside and remove the inline specifier. Your code cannot be inlined anyway.


Share the Post: