CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    I'd like to create with vector many persons:
    person1
    person2
    ...

    "people" could/should be the iterator, shouldn't it?

    In
    Code:
    for(int i=0; i<people.size(); i++)
    	{
    		cout<<(*people[i]).get_name();
    	}
    I thought "people" as an iterator is already working!?
    people isn't an iterator, it's a vector. That code doesn't directly use iterators.

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    I'd like to create with vector many persons:
    person1
    person2
    Code:
    #include <vector>
    #include <string>
    
    class Person
    {
        int age;
        int weight;
        int gender;
        int height_in_inches;
        std::string name;
        std::string country_of_birth;
    //...
        //.. add public members
    };
    
    typedef std::vector<Person> PersonVector;
    
    int main()
    {
        PersonVector pV;
        pV.push_back( Person() );
    }
    The Person class describes a single person. The PersonVector is an alias for a vector of Person.

    So what do you not understand about the code above? You should start with something more coherent such as the code above.

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Apr 1999
    Posts
    27,449

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    I'm not getting to the core of all the matter.

    Whats so wrong about a little 'reverse engineering' ?
    What exactly are you "reverse engineering"?

    You don't learn C++ this way -- that's the cold, hard facts. Take it from me, a person who has taught C++.

    Regards,

    Paul McKenzie

  4. #19
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    Whats so wrong about a little 'reverse engineering' ?
    Well, for one thing it doesn't appear to be working very well so far.

  5. #20
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    I'm not getting to the core of all the matter.

    Whats so wrong about a little 'reverse engineering' ?
    What's wrong is you're looking at things you don't understand and asking questions that don't make any sense. If you want to learn the language, and there's a very steep learning curve, get a good book that takes you through the basics in a well organized, methodical manner. You'll never learn C++ by looking at code and trying to guess what it does.

  6. #21
    Join Date
    Dec 2011
    Posts
    11

    Re: problem with push_back

    I'm sorry.
    It was not my intention to be impolite or bumptious.
    I just wondered what some people could tell me if I'd ask such questions.
    I appreciate your criticism!

  7. #22
    Join Date
    Dec 2011
    Posts
    11

    Re: problem with push_back

    GCDEF, I agree with you.
    I want to make headway by different approaches. And I'm really trying to code my own stuff.

  8. #23
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    I'm sorry.
    It was not my intention to be impolite or bumptious.
    I just wondered what some people could tell me if I'd ask such questions.
    I appreciate your criticism!
    Nobody said you were impolite, just embarking on a journey that would prove frustrating and fruitless.

  9. #24
    Join Date
    Dec 2011
    Posts
    11

    Re: problem with push_back

    Many thanks for the example, Paul McKenzie!

  10. #25
    Join Date
    Apr 1999
    Posts
    27,449

    Re: problem with push_back

    Quote Originally Posted by Fellow View Post
    I'm sorry.
    It was not my intention to be impolite or bumptious.
    You were not impolite.

    It's that the C++ language isn't something that can be learned informally without structure. Some try but then get tangled in all sorts of knots trying to write the simplest of programs.

    Others try to write advanced programs (for example using templates), but are lacking in the basic C++ fundamentals required to write such code (the "cherry-pickers" suffer from this fate).

    A good book or set of books should be used, so that you understand each concept before moving on to another concept.

    Regards,

    Paul McKenzie

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured