944,048 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5739
  • C++ RSS
Mar 2nd, 2007
0

Array Initialization

Expand 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.

what do i do ? where do i initialize the array. Please help. this is just the thing holding me back.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
livingsword is offline Offline
18 posts
since Jan 2007
Mar 2nd, 2007
0

Re: Array Initialization

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"
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Mar 2nd, 2007
0

Re: Array Initialization

Click to Expand / Collapse  Quote originally posted by WaltP ...
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'.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
livingsword is offline Offline
18 posts
since Jan 2007
Mar 2nd, 2007
0

Re: Array Initialization

it shouldn't happen. try
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. int main () {
  3. int test [5]={0};
  4. cout<<test[0];
  5. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkAngel is offline Offline
3 posts
since Feb 2007
Mar 2nd, 2007
0

Re: Array Initialization

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...
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Enter string to the next line
Next Thread in C++ Forum Timeline: Program to display System date and Time in VC++ 6.0





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC