Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Array handling problems:

Array handling problems:

Scheduled Pinned Locked Moved Managed C++/CLI
helpdata-structuresquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luhfluh
    wrote on last edited by
    #1

    :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?

    C 1 Reply Last reply
    0
    • L luhfluh

      :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?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • C Christian Graus

        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

        L Offline
        L Offline
        luhfluh
        wrote on last edited by
        #3

        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(

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups