C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 26th, 2010, 01:38 PM
akhyls akhyls is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Location: turkey
Posts: 8 akhyls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old February 26th, 2010, 01:50 PM
Oler1s Oler1s is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2006
Posts: 2,270 Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 15 h 34 m 57 sec
Reputation Power: 1735
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.

Reply With Quote
  #3  
Old February 26th, 2010, 02:03 PM
akhyls akhyls is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Location: turkey
Posts: 8 akhyls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old February 26th, 2010, 03:22 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
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?
__________________

Reply With Quote
  #5  
Old February 28th, 2010, 10:04 AM
akhyls akhyls is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Location: turkey
Posts: 8 akhyls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #6  
Old February 28th, 2010, 03:36 PM
jwdonahue's Avatar
jwdonahue jwdonahue is offline
Bellevue WA, USA
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 3,398 jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 48 m 17 sec
Reputation Power: 886
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/

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Array Of Class Objects

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap