Programming: February 2005 Archives

Class or Struct?

| | Comments (0)
I stumbled over an interview with Bjarne Stroustrup and he said something clever: "My rule of thumb is that you should have a real class with an interface and a hidden representation if and only if you can consider an invariant for the class." Bjarne Stroustrup I find this a very good rule of thumb.

STL: Bad Behaviour

| | Comments (0)
We've been arguing at work about whether it's ok to use the & operator while indexing an STL vector. I'm currently working with a compiler that is throwing errors at me for doing it, so I finally has backup for my arguments *sigh*. It's quite easy to learn the 'right' way: Never do: [cpp] // Bad m_vecSound.erase( &m_vecSound[i] ); [/cpp] Do: [cpp] // Good m_vecSound.erase( m_vecSound.begin() + i ); [/cpp] May be obvious to some but apparently not to all. :o
I think it's handy to use my favourite IDE Visual Studio .Net 2003 even when I do gcc development. It's quite easy to do a makefile project, and add the relevant paths to the IDE so it can find the necessary binaries for compiling and such. But I found it rather annoying that I don't have clickable errors and warnings since I'm quite used to that (cough lazy cough). How nice there is an easy hack you can do though. Look! Open up cc1.exe (and cc1plus.exe if you use c++) in your favourite hex editor. Then search for the string "%s:%d: " (don't forget the space) and replace with "%s(%d):". Then save the files and you're done.

About this Archive

This page is a archive of entries in the Programming category from February 2005.

Programming: July 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.