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


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

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