The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Array Of Class Objects
Discuss Array Of Class Objects in the C Programming forum on Dev Shed. Array Of Class Objects C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 26th, 2010, 01:38 PM
|
|
Registered User
|
|
Join Date: Feb 2010
Location: turkey
Posts: 8
Time spent in forums: 2 h 28 m 29 sec
Reputation Power: 0
|
|
|
Array Of Class Objects
how can we create array of class objects, send them to the function?
|

February 26th, 2010, 01:50 PM
|
|
|
|
Replace "class objects" with "integers" and answer that question. Now, can you answer your own question?
__________________
When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.
Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
|

February 26th, 2010, 02:03 PM
|
|
Registered User
|
|
Join Date: Feb 2010
Location: turkey
Posts: 8
Time spent in forums: 2 h 28 m 29 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Oler1s Replace "class objects" with "integers" and answer that question. Now, can you answer your own question? |
if there is a class called Car
can we say
Car c[4];
and when we want to sent the array to a function sholud we say
function( c[4] )?
And when we want to send the only the fourth object of the array should we say
function( c[4] )
how do we distinguish them. i am very confused 
|

February 26th, 2010, 03:22 PM
|
|
Closet coder
|
|
Join Date: Feb 2005
Location: Plantation, FL <---south florida
|
|
Quote: | Originally Posted by akhyls if there is a class called Car
can we say
Car c[4];
and when we want to sent the array to a function sholud we say
function( c[4] )?
And when we want to send the only the fourth object of the array should we say
function( c[4] )
how do we distinguish them. i am very confused  |
first thing first, what language are you using?
for above, lets say there are 2 functions, one that needs the full array of cars and the other just takes a single car (im doing this in c++)
Code:
void OperateOnArray( Car c[], int array_length );
void OperateOnOneCar( Car single_car);
Car car_array[] = {Car("ford"), Car("nissan")};
OperateOnArray(car_array, 2);
OperateOnOneCar(car_array[1]);
make sense?
__________________
|

February 28th, 2010, 10:04 AM
|
|
Registered User
|
|
Join Date: Feb 2010
Location: turkey
Posts: 8
Time spent in forums: 2 h 28 m 29 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by nattylife first thing first, what language are you using?
for above, lets say there are 2 functions, one that needs the full array of cars and the other just takes a single car (im doing this in c++)
Code:
void OperateOnArray( Car c[], int array_length );
void OperateOnOneCar( Car single_car);
Car car_array[] = {Car("ford"), Car("nissan")};
OperateOnArray(car_array, 2);
OperateOnOneCar(car_array[1]);
make sense? |
yes i understand thanks for help 
|

February 28th, 2010, 03:36 PM
|
 |
Bellevue WA, USA
|
|
Join Date: May 2004
Location: Bellevue Washington, USA
|
|
Actually, OperatOnOneCar() is redundant. You can call OperateOnArray( &car_array[1], 1 ) instead. In C++ it would you can also use function overloading and have something along the lines of:
Code:
void OperateOnCar( Car &single_car ) ;
void OperateOnCar( Car *c, size_t items ) ;
void OperateOnCar( std::vector<Car> &rvec ) ;
Car car_array[] = { Car("Ford"), Car("Nissan") } ;
std::vector<Car> car_vec( car_array, car_array + 1 ) ;
OperateOnCar( car_array, 2 ) ;
OperateOnCar( car_array[1] ) ;
OperateOnCar( car_vec ) ;
__________________
My worst nightmare was a pointless infinite loop.
Work in progress; don't poke the curmudgeon!
http://www.odonahue.com/
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|