Array handling problems:
-
:confused:Hi, I'd need some help with my commandline application. Its basically a contact list application which allows user to choose to add two types of contacts (club and client). I wrote the classes for these two. So when the choice is made, a function ADD() is invoked which creates this arrays of type club or client. The problem is as these object arrays are created within the ADD() function, they have only a local scope so I tried referencing its values so that in the end, the main() function can have have access to them. But unfortunately the message from the compiler is "referencing an array...." Is it possible to reference an array so that its scope becomes virtualy global? If not, what other ways can a variable object within a function be accessed easily by other functions?
-
:confused:Hi, I'd need some help with my commandline application. Its basically a contact list application which allows user to choose to add two types of contacts (club and client). I wrote the classes for these two. So when the choice is made, a function ADD() is invoked which creates this arrays of type club or client. The problem is as these object arrays are created within the ADD() function, they have only a local scope so I tried referencing its values so that in the end, the main() function can have have access to them. But unfortunately the message from the compiler is "referencing an array...." Is it possible to reference an array so that its scope becomes virtualy global? If not, what other ways can a variable object within a function be accessed easily by other functions?
Is this a C++/CLI question, or just C++. Either way, in this forum or the C++ forum, it sounds like you need to post your code. You can return anything from a method, you can't declare anything in a method and give it scope outside the method without returning it. Returning a pointer makes the most sense ( saves a copy being made ).
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Is this a C++/CLI question, or just C++. Either way, in this forum or the C++ forum, it sounds like you need to post your code. You can return anything from a method, you can't declare anything in a method and give it scope outside the method without returning it. Returning a pointer makes the most sense ( saves a copy being made ).
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Hi again...The code is below and i hope it helps clarify my enquiry.I'm new to C++ and all help and suggestions are much appreciated. *******************code for contact list******************** #include #include using namespace std; class BasicAd{ protected: string name; string home_address; public: void BasicAd::setValues(string n, string h){ name = n; home_address = h; }; void BasicAd::getValues(){ cout<<"name : "<>choice; if(choice==1){ cout<<"\nEnter number of items for clubDir: "; cin>>size; for(int i=0; i>name; cout<<"home address: "; cin>>ha; cout<<"member name: "; cin>>mn; cout<<"date joined:"; cin>>dj; cout<<"\n"; club[i].setValues(name, ha, mn, dj); }; cout<<"\nThe Contact Details addded...."; } else if(choice==2){ cout<<"\nEnter number of items for clientDir: "; cin>>size; for(