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. C / C++ / MFC
  4. Passing the address of an object in to a Function

Passing the address of an object in to a Function

Scheduled Pinned Locked Moved C / C++ / MFC
databasegraphicshelpquestionlearning
2 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.
  • B Offline
    B Offline
    bhangie
    wrote on last edited by
    #1

    Hi there Sorry for the Slopy Subject line!. What i whant to know is the following. I have declared a vector of person Objects vector(person) people; //in main I have a confrence class class conf { public: conf(const string &nm, int d); void set_venue(venue *); void cancel_venue(); private: string conference_name; int duration; venue * pvenue; //pointer to venue class } I Have added a data member to the conf class which is a vector of pointers to person vector(person *) registered; and the following member function to register a person who choose to attend a conference. void register_person(????); So this is what i must do, ok so person objects where added to people //vector(person)people; The person running the program gets to decide who will attend a certian confr thus needing to register this person for the confr. By index how would i pass the address of the specified person object to my register_person(????); function and get register_person(????); to append this person object to my registration vector(Containing only registered persons). I am knot sure about this-> register_person(person & registered)? needs to recieve the address of a specified(index) person object. Help me:~ Education begins a gentleman, conversation completes him ;)

    J 1 Reply Last reply
    0
    • B bhangie

      Hi there Sorry for the Slopy Subject line!. What i whant to know is the following. I have declared a vector of person Objects vector(person) people; //in main I have a confrence class class conf { public: conf(const string &nm, int d); void set_venue(venue *); void cancel_venue(); private: string conference_name; int duration; venue * pvenue; //pointer to venue class } I Have added a data member to the conf class which is a vector of pointers to person vector(person *) registered; and the following member function to register a person who choose to attend a conference. void register_person(????); So this is what i must do, ok so person objects where added to people //vector(person)people; The person running the program gets to decide who will attend a certian confr thus needing to register this person for the confr. By index how would i pass the address of the specified person object to my register_person(????); function and get register_person(????); to append this person object to my registration vector(Containing only registered persons). I am knot sure about this-> register_person(person & registered)? needs to recieve the address of a specified(index) person object. Help me:~ Education begins a gentleman, conversation completes him ;)

      J Offline
      J Offline
      Jnewg5
      wrote on last edited by
      #2

      If your prototype for register_person is as you stated "register_person(person & registered", then all you really need to do is do "registered.push_back(®istered)". If you are uncertain of the number of persons, you should be going to the heap for allocation. Then you should be doing "news" on the Person objects and thus your prototype for register_person should be "register_person(person * registered)". You would then just need to do "registered.push_back(person)".

      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