Array Initialization

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2007
Posts: 18
Reputation: livingsword is an unknown quantity at this point 
Solved Threads: 0
livingsword livingsword is offline Offline
Newbie Poster

Array Initialization

 
0
  #1
Mar 2nd, 2007
i want to initialize an array(set all elements to 0) . The array is to be used by different functions which r defined outside the class. obviously i cant initialize it in the class. and if i do it in a constructor or main(), it isnt recognised by all the functions outside the class using it.

what do i do ? where do i initialize the array. Please help. this is just the thing holding me back.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Array Initialization

 
0
  #2
Mar 2nd, 2007
Originally Posted by livingsword View Post
i want to initialize an array(set all elements to 0) . The array is to be used by different functions which r defined outside the class. obviously i cant initialize it in the class. and if i do it in a constructor or main(), it isnt recognised by all the functions outside the class using it.
Sure it is. You probably did it wrong if it's not working. Define what you mean by "it isnt recognised"
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 18
Reputation: livingsword is an unknown quantity at this point 
Solved Threads: 0
livingsword livingsword is offline Offline
Newbie Poster

Re: Array Initialization

 
0
  #3
Mar 2nd, 2007
Originally Posted by WaltP View Post
Sure it is. You probably did it wrong if it's not working. Define what you mean by "it isnt recognised"
if i initialize the array in main() or constructor, the other functions which use that array give error : 'array not defined'.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 3
Reputation: darkAngel is an unknown quantity at this point 
Solved Threads: 0
darkAngel darkAngel is offline Offline
Newbie Poster

Re: Array Initialization

 
0
  #4
Mar 2nd, 2007
it shouldn't happen. try
  1. #include <iostream>
  2. int main () {
  3. int test [5]={0};
  4. cout<<test[0];
  5. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,610
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 465
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Array Initialization

 
0
  #5
Mar 2nd, 2007
Originally Posted by livingsword View Post
if i initialize the array in main() or constructor, the other functions which use that array give error : 'array not defined'.
Thats because they can't see the array or the array is out of scope for them. Post the code which displays this peculiar behaviour and we will see what can be done...
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC