dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Beginner
Dec 1, 1999

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Array of Objects

Question:
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"?

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

 
void func( vector < Foo >& vf);
int func2()
{
  vector < Foo > 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.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date