|
-
January 27th, 2012, 12:32 PM
#16
Re: problem with push_back
 Originally Posted by Fellow
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.
-
January 27th, 2012, 12:37 PM
#17
Re: problem with push_back
 Originally Posted by Fellow
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
-
January 27th, 2012, 12:39 PM
#18
Re: problem with push_back
 Originally Posted by Fellow
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
-
January 27th, 2012, 12:40 PM
#19
Re: problem with push_back
 Originally Posted by Fellow
Whats so wrong about a little 'reverse engineering' ?
Well, for one thing it doesn't appear to be working very well so far.
-
January 27th, 2012, 12:48 PM
#20
Re: problem with push_back
 Originally Posted by Fellow
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.
-
January 27th, 2012, 02:40 PM
#21
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!
-
January 27th, 2012, 02:46 PM
#22
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.
-
January 27th, 2012, 02:47 PM
#23
Re: problem with push_back
 Originally Posted by Fellow
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.
-
January 27th, 2012, 02:57 PM
#24
Re: problem with push_back
Many thanks for the example, Paul McKenzie!
-
January 27th, 2012, 02:59 PM
#25
Re: problem with push_back
 Originally Posted by Fellow
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|