Why a list? vector would be much better in this situation.
Well you don't know what all kind of mad things he's doing with his list... ;D
But yeah a std::vector is mostly preferable. So is the use of smart pointers over raw pointers.
std::vector<std::unique_ptr<ButtonBase>>
Why do you say a vector would be better? List is faster for iterating through than a vector.
I don't know from where you got that impression, but as cire said, std::vector are faster for iteration, because they reduce cache misses, since the memory is allocated contiguous. Although for vector of pointers it doesn't matter too much, since only the memory of the pointers are allocated contiguous, but the actual data (i.e. buttons) are 'randomly' distributed in memory.
Also, I've seen people talk about these stl pointer classes, what are they exactly?
They are called smart pointers and are one of the bigger parts of C++11. But some where already introduced with the TR1 and thus many not uptodate compiler, also "support" them already (e.g. VS2010). They should basically replace manual memory management (calling new and delete by hand) and thus drastically reduce the complexity of such, by using RAII (see this thread (http://en.sfml-dev.org/forums/index.php?topic=9359.0) with example).
Specially std::unique_ptr works kind of like a raw pointer, e.g. you can use
std::unique_ptr<BaseClass> ptr = std::unique_ptr<BaseClass>(new DerivedClass);
The biggest difference being that there can always be just one unique_ptr that holds the class instance and if you want to 'copy' the pointer you'll have to use std::move.
At best you use Google and find some more information, it's quite important stuff, unfortunately there aren't many books yet.
I've always read people saying lists are faster for going through and vectors are better if you need a specific thing. Or maybe that was just adding and removing. Or maybe I'm just dumb.
Well, in this case stop reading, and make your own opinion ;)
- vector iteration
current++;
// operations involved:
- one addition
- one assignment
-> probably optimized to a single machine instruction
// other things to consider:
- the next element is contiguous to the current one, so it is
most likely already loaded in the processor's cache
- list iteration
current = current->next;
// operations involved:
- one indirection (resolving 'current->')
- one read ('current->next')
- one assignment
// other things to consider:
- the next element can be anywhere in memory, so it is
most likely *not* in the processor's cache
Note that this is very approximative, I'm not an expert in low-level machine instructions.