0

Sorry for the messy title, I'm not quite sure how I should word it to better get my meaning across.

So, I have

struct Person
{
    std::string id_ = NO_ID;
    int height_ = NO_HEIGHT;
    std::vector<Person*> parents_{nullptr, nullptr};
    std::vector<Person*> children_;
};

and I want to be able to populate a map of Person(s) with data.

I made

using Personmap = std::map<std::string, Person >;

for it, but I'm not sure whether I should use *Person or Person here.

When I use Person, I at least know how to work with it, but when I try populating the vectors with data using anything like

    persons_[child].parents_[0]  = ( persons_[parent_1] );

or similar, I'm getting an error because I'm trying to populate it with Person instead of Person*. Apart from the error message, I don't quite understand their difference and I'm not sure what I should utilize to make it work. The struct is not something I can change, but anything else here is free for scrutiny

Grak
  • 99
  • 1
  • 12
  • 5
    Perhaps you need [a good book or two](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) to read about pointers? – Some programmer dude Mar 17 '18 at 12:06
  • 1
    Chances are you don't need a vector of pointers. – Ron Mar 17 '18 at 12:08
  • [What are the barriers to understanding pointers and what can be done to overcome them?](https://stackoverflow.com/q/5727/995714), [When to use pointers, and when not to use them](https://stackoverflow.com/q/1327943/995714) – phuclv Mar 17 '18 at 12:08
  • The whole idea to have parents and children as pointers so that they point to other structures of people. Where and how you store those structures is up to you – Killzone Kid Mar 17 '18 at 12:08
  • @Ron I think OP needs them https://stackoverflow.com/questions/49334779/populating-a-vector-of-objects-within-a-class – Killzone Kid Mar 17 '18 at 12:09

0 Answers0