Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Feb 2002
Offline Last Active Oct 06 2013 05:03 AM

Posts I've Made

In Topic: ? about arrays

26 June 2012 - 02:33 AM

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

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).

In Topic: Java vs Python

26 June 2012 - 02:27 AM

I will just say that any performance considerations aside, it IS very difficult to manage a large python application. With Java or any other compiled language the compiler will find many of your errors for you. With python you will loath to change any interface or the signature of any function. Those changes will affect many different source files and you'll be debugging those changes instead of just fixing them before you can build it.

This is a case for automated unit testing, which should be carried out in any "large" application. Not that it always is, of course. The point is that process and procedure is just as significant to project success as is choice of technology.

Oh yeah, its horrific. IDLE is a real poor IDE, and there aren't really any better ones.

Eclipse + pydev is better.

In Topic: Observer pattern question

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.

In Topic: Iterator list corrupted (even with correct references)

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:
void deleteTown( const std::string & townName );
Any iterators which are acquired to carry out the delete should not live beyond the scope of deleteTown.

In Topic: OOP class problems

12 January 2007 - 03:23 AM

This is likely because you are defining objects in header files, and then including those header files in multiple places, leading to the same code being input to the linker from more than one object file. In order to correct this, you need to ensure that you have only declarations (not definitions) in your header files, and the corresponding definitions need to be in just one place. Any good C++ text will explain how to do this.