User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 429,965 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,552 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2311 | Replies: 4
Reply
Join Date: Jan 2007
Posts: 18
Reputation: livingsword is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
livingsword livingsword is offline Offline
Newbie Poster

Help Array Initialization

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Posts: 2,724
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 224
Moderator
WaltP's Avatar
WaltP WaltP is online now Online
Posting Maven

Re: Array Initialization

  #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"
Age is unimportant -- except in cheese
Reply With Quote  
Join Date: Jan 2007
Posts: 18
Reputation: livingsword is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
livingsword livingsword is offline Offline
Newbie Poster

Re: Array Initialization

  #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  
Join Date: Feb 2007
Posts: 3
Reputation: darkAngel is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
darkAngel darkAngel is offline Offline
Newbie Poster

Re: Array Initialization

  #4  
Mar 2nd, 2007
it shouldn't happen. try
#include <iostream>
int main () {
    int test [5]={0};
    cout<<test[0];
}
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,871
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 345
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Array Initialization

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

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC