hello there guys, was wondering if anyone could help me,im new to C++ and at the moment im trying to make an array of people which then has either an array or list of other variables, it would be an array of people (this would have their details such as name age dob) with a list of their accounts (bank account internet account etc each with their own set of variables such as balance), i can make an array of the account or even the people but i dont know how to give a person within an array an account, as a person can have many accounts, also im not to sure how you would delete a person from the array and even more unsure how you would keep a person but delete one of many accounts. hope this makes sence to someone could really use a hand thanks.

If you're just getting started with C++, then the following advice may seem heretical; but long experience has convinced me that it is sound:

Don't use arrays. Use vectors (i.e. std::vector<T>) instead.

The reason is that arrays aren't really objects, which means that there are various restrictions on how you can use them: You can't assign them; if you try to pass one to a function, it magically transmutes into a pointer, the size of an array has to be a constant (unless you take charge of memory allocation yourself by using new and delete), and so on.

If you use std::vector and std::list instead, you will make your life much easier.

If you're just getting started with C++, then the following advice may seem heretical; but long experience has convinced me that it is sound:

Andy has a lot of experience with C++; and for what its worth, I wholly agree. C++ gives you a lot of very nicely behaved, very useful tools that you would be silly to avoid. Like using a stone axe instead of a skill saw.

>>would be silly to avoid

I would generally agree, but if OP is trying to learn the semantics of arrays or even C++, then he needs to get a good grasp of the basics before using something like vectors. So that he knows exactly what each function will do for him.

>>I would generally agree, but if OP is trying to learn the semantics of arrays or even C++, then he needs to get a good grasp of the basics before using something like vectors. So that he knows exactly what each function will do for him.

It's easier to learn vectors first. I know because I've taught it both ways, and I could tell where my students had trouble from the questions they asked.

It's easier to learn vectors first. I know because I've taught it both ways, and I could tell where my students had trouble from the questions they asked.

Your a teacher? A professor? Cool, didn't know that. Essentially when you teach them about vectors, you are enhancing their intuition about what a function does, and maybe giving them insight on how to implement it as well. But this can be achieved through teaching as well. I might be biased because I wasn't taught vectors first than arrays. But since you are a teacher, you have more experience with this kind of stuff, so I'll step aside.

This article has been dead for over six months. Start a new discussion instead.