I should prefer stack allocation to heap allocation. It's better to pass by value (especially if you're creating new objects — but at the same time, if you return by base class, your object will be sliced), or at least by reference than passing pointers (although you can't create a vector of references).
I read all of this carefully, and now I feel that I know less that I knew before. I don't have a slightest idea about how to write a code that, IMO, should be trivial, while respecting the best practices mentioned in all of these well-written and thought-through answers.
Here's what I want to implement. (I don't pretend that it's correct C++, but I just want to convey the idea).
// This thing is purely virtual!
class BaseStuff { }
// Has important behaviour and data members that shouldn't be sliced
class SomeStuff : public BaseStuff { }
// Don't slice me plz
class OtherStuff : public BaseStuff { }
BaseStuff CreateStuff()
{
// falls a set of rules to create SomeStuff or OtherStuff instance based on phase of the moon
}
std::vector<BaseStuff> CreateListOfStuff()
{
// calls CreateStuff a lot
}
public static void main()
{
List<BaseStuff> allTheStuff = CreateListOfStuff();
// to things with stuff
}