![]() |
|
|
| Subject:
Passing an array of objects in C++
Category: Computers > Programming Asked by: jpvoodoo-ga List Price: $5.00 |
Posted:
08 Oct 2003 19:51 PDT
Expires: 07 Nov 2003 18:51 PST Question ID: 264446 |
In C++ how do you pass an array of objects and access their member functions in the function? | |
|
|
| There is no answer at this time. |
|
| Subject:
Re: Passing an array of objects in C++
From: malachite-ga on 09 Oct 2003 10:06 PDT |
// Here's a sample c++ program that passes an array
void foo( int iArray[] )
{
printf( "num=%d", iArray[3] );
}
int main(int argc, char* argv[])
{
int myArray[10];
for( int x=0; x<10; x++ )
{
myArray[x]=x*5;
}
foo( myArray );
return 0;
} |
| Subject:
Re: Passing an array of objects in C++
From: malachite-ga on 09 Oct 2003 10:13 PDT |
// For objects, use an array of pointers
class dude
{
public:
dude(){}
void foo(){printf("dude's foo");}
};
void foo( dude* dudeArray[] )
{
dudeArray[3]->foo();
}
int main(int argc, char* argv[])
{
dude* the_dudes[10];
for( int x=0; x<10; x++ )
{
the_dudes[x] = new dude();
}
foo( the_dudes );
return 0;
} |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |