Hey,
Just curious if I have coded this nicely. Its a small snippet of some code that works with my inventory in my game. Basically the inventory is just a holder of a ItemWindow. This makes sense to me because you don't want to have to write separate code for the shops and the bank ect ect.
you could prepend 'm_' or just '_' to your member variables and then remove all of the 'this->'. that way you could instantly see that your dealing with member variables.
@ne555
He is allocating and storing a new item. That seems me appropriate, and not what you complained about in the link. (Or do I misread?)
@mutexe
I personally think that m_ stuff is uglier and harder to parse. In the original code, the this-> isn't even really necessary, as you show by use in your patched example.
Personally, I think that "I'm a member"-style quantifiers should stand out somewhat to make them less visually crowded with the identifier, which this-> does without mangling the identifier.
> He is allocating and storing a new item
In that case I would want to see the type of `itemSlot' container<ItemSlot*> is ugly and would be error-prone as discussed (the memory management would not be in `addItem()' but somewhere else) container< smart_ptr<ItemSlot> > would be innefficient
It would be necessary if it is planning on using polymorphism on the elements
createItem is seperated from the constructor because its neater. It says it in black and white createItem. Anyone looking at this code knows exactly what is going on. If I allowed the item to be created in the constructor it would be confusing. I am also using a vector because the ItemWindows number of item slots needs to be set at runtime.