Google Answers Logo
View Question
 
Q: Passing an array of objects in C++ ( No Answer,   2 Comments )
Question  
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?

Request for Question Clarification by efn-ga on 09 Oct 2003 11:44 PDT
Do the comments from malachite-ga answer your question adequately?
Answer  
There is no answer at this time.

Comments  
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;
}

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy