Thread: Container/class question

  1. #1
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309

    Container/class question

    Ok, so say I have a class such as this:
    Code:
    class fruit
    {
    private:
    int weight;
    string name;
    string color;
    }
    And I had a container for it like this:
    Code:
    vector<fruit> Thing;
    Assume that I had a public function that would set a name, weight, and color based on three parameters.

    Now, how would I add an instance of "fruit" (containing weight, name, and color) to the vector Thing?

    Thing.push_back(44, "bleh", "sdflkj") wouldn't work (would it?).

    What about something like, "Thing.public_function(44, "name", "color")? Then could I acess that through "Thing[0]"?

    *Sorry if this post sounds extremly stupid*

    EDIT:Ignore the above, I figured it out. I am an idiot
    Last edited by 7smurfs; 03-31-2005 at 01:10 PM.
    To code is divine

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Quote Originally Posted by 7smurfs
    EDIT:Ignore the above, I figured it out. I am an idiot
    Why idiot, I think most of us (in the begining) figure something almost immediately after posting. You need to know that sometime helps to write question on the paper and then it's easier to see what the problem really is and therefore how to solve it. It's at least my experience.
    Relax and enjoy coding
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM