0

What I was trying to do was make a list of them with

Item *itm = new Item();
_lst.push_front(&itm);

lst was made made in the header

std::list<int> _lst;

I am trying to learn c++ on my own so any advise would be great.

edit1) doesn't &itm give the pointers location in memory which would be an int?

edit2) The fact that i should not be learning c++ on my own does not help with the pointer problem

mrm9084
  • 430
  • 1
  • 3
  • 12
  • 5
    If it's a list of `int`, you're not going to have much luck putting an `Item**` on it... – Borealid Feb 03 '12 at 03:44
  • 3
    You can learn C++ on your own, but without [a good book](http://stackoverflow.com/q/388242/46642), it won't be easy. – R. Martinho Fernandes Feb 03 '12 at 03:52
  • In response to your edit, **no**. Pointers are not `int`s. (In response to your other edit, you'd know that if you weren't learning C++ on your own...) – Cody Gray - on strike Feb 03 '12 at 03:55
  • 1
    "The fact that i should not be learning c++ on my own does not help with the pointer problem" Yes it does. It tells you to forget your pointer problem and go read a book. Once you've done that, you'll look back on this question and know why not many think much of it. You said, "any advise would be great." There's my advice. – Nicol Bolas Feb 03 '12 at 04:07

1 Answers1

2

I'd suggest simply using

std::list<Item**> _lst;

Do you need the double indirection? Can't you do with a list like this:

std::list<Item*> _lst;

Of course, you'd have to push back itm instead of &itm if you wanted to do that. Are you sure you need a list and not a vector or a deque? As the comments suggested, get a good C++ book to help things along.

After reading the comment on my post by R. Martinho Fernandes, I have to suggest std::list<Item> _lst; as a good alternative as well. It really depends on what you need, as I said earlier.

I hope this helps.

batbrat
  • 5,155
  • 3
  • 32
  • 38