Arrays in C++ are a degenerate data structure which you should avoid, at least if working code is a priority. You might consider finding a tutorial which teaches a more modern approach to C++ (Accelerated C++ for instance).Hello I'm following this tutorial about arrays and I understand how they are declared and the several ways to initialize them, what confuses me is when I can't do
...
- Viewing Profile: Reputation: SabreMan
Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics
Community Stats
- Group Members
- Active Posts 3,867
- Profile Views 442
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
#4952944 ? about arrays
Posted by SabreMan
on 26 June 2012 - 02:33 AM
#4952940 Observer pattern question
Posted by SabreMan
on 26 June 2012 - 02:14 AM
As usual, it depends. There's several factors you may want to think about, such as whether you want to pass arguments with an event, if you want your observer framework to be fully typesafe, whether it needs to be threadsafe, etc. If you're using Boost and you're not so bothered about your own implementation of observer, then boost::signals2 is worth a look.
#4941395 Iterator list corrupted (even with correct references)
Posted by SabreMan
on 19 May 2012 - 04:21 AM
It's unclear from your explanation what the precise problem is, but you may find it easier to get your code working correctly if you avoid working with bare pointers as much as possible. It's also not entirely obvious that you need your town objects to be heap-allocated.
Consider storing the town objects by value. If you are convinced you need them to be heap-allocated, then prefer to use a suitable smart pointer. Boost's shared_ptr or weak_ptr should be a good option.
Also consider using std::vector rather than std::list, which is a general recommendation: Always prefer std::vector as the default choice for a sequence container, unless there's a clear overriding reason to use something else.
Finally, don't hold onto iterators, or use them to identify an object. If you want to remove a town from a container, then do so using the identifier of the town, for example the town name (assuming the name is a unique identifier). So the signature of your deleteTown function could be:
Consider storing the town objects by value. If you are convinced you need them to be heap-allocated, then prefer to use a suitable smart pointer. Boost's shared_ptr or weak_ptr should be a good option.
Also consider using std::vector rather than std::list, which is a general recommendation: Always prefer std::vector as the default choice for a sequence container, unless there's a clear overriding reason to use something else.
Finally, don't hold onto iterators, or use them to identify an object. If you want to remove a town from a container, then do so using the identifier of the town, for example the town name (assuming the name is a unique identifier). So the signature of your deleteTown function could be:
void deleteTown( const std::string & townName );Any iterators which are acquired to carry out the delete should not live beyond the scope of deleteTown.
- Home
- » Viewing Profile: Reputation: SabreMan

Find content