evian's Profile User Rating: -----

Reputation: 0 Apprentice
New Members
Active Posts:
3 (0 per day)
18-November 11
Profile Views:
Last Active:
User is offline Jun 08 2012 05:59 AM

Previous Fields

Dream Kudos:
Icon   evian has not set their status

Posts I've Made

  1. In Topic: Store Class Objects in vector

    Posted 8 Jun 2012


    No problem- you're right that it would've been useful if an example had been provided about random access, but, then again, the title of this discussion was "Storing Class Objects in Vector," not "Retrieving Class Objects in Vector," so more emphasis was placed on the former. :) And, besides, once you've implemented all the code necessary to create the class and store the code, it's very simple to implement the random access part...


    View Postciccioriccio, on 08 June 2012 - 12:51 AM, said:

    Hi, Evan
    Thank you for your useful answers. As soon as possible I'll try your suggestions. It seems to me that the scope of the code of Mr. Nirvanarupali is to show an elegant method to manage data in a structure with vector. In this case it should be useful to complete the dissertation with an example about random access.
  2. In Topic: Store Class Objects in vector

    Posted 7 Jun 2012


    You'd want to create getter functions in the class to access the data located in the private class variables stored within the vector, to pass it into the main program . The code contains class setter methods already in the form of setName, setAge, setHeight- this is how it passes the information from the user and to the private class variables. Now, you need the data to go the other way after it's been stored. So, you'd create a getter function in the "public" portion of the class code, just like the setter functions are already declared. A sample getter function would look like:
    string getName { return name; }

    You have to declare one for each private class variable you want to retrieve data from. And then to access specific elements of the stored info in the vector in a random fashion, you'd give the below command in the main program, below the part where you input all the user info:
    cout << list.at(n).getName(); //where "n" is the vector index position you wish to access

    What you're doing is accessing the vector named "list" at a specific index position and calling the getName function to access the specific data stored at that position (in this example, you have three pieces of data stored at that index position). Just remember that vector index numbering starts at 0 and not 1, so to call the first record you'd access index position 0. Hope that helps!


    View Postciccioriccio, on 07 June 2012 - 09:34 AM, said:

    I'm a newby of C++ and I've found very useful this tutorial. But
    it should be useful (if it's possible) to show how to access in a random way to one element of the structure. Suppose there are ten friends recorded in the list and I wan to the data of the fifth element. How to?
    Thanks in advance.


My Information

Member Title:
New D.I.C Head
Age Unknown
Birthday Unknown

Contact Information

Click here to e-mail me


evian hasn't added any friends yet.


evian has no profile comments yet. Why not say hello?