2008-10-25

Namespaces

Woopsi now has a new namespace: “WoopsiUI”. All of the classes are now part of this namespace. This will impact user code in a number of ways. Firstly, you might be doing this in your .h files:


#ifndef _MYCLASS_H_
#define _MYCLASS_H_

#include "woopsi.h"

class Button;

class MyClass {
...
}

#endif

Declaring the Button class won’t work any more. as it is now in a different namespace. You have two options. You can do this instead:


namespace WoopsiUI {
    class Button;
}

This seems like a nasty workaround to me, as you shouldn’t really be changing the WoopsiUI namespace, even if all you’re doing is declaring something that’s already in there. Alternatively, you can just #include the “button.h” file.

Trying to do this doesn’t work, despite how logical it looks:


class WoopsiUI::Button;

I imagine the reason for this is that prefixing a class name with the namespace means you’re trying to access something that already exists, not define something new.

You’ll probably find that you need to add this near the top of your .h files:


using namespace WoopsiUI;

Purists will tell you that what you should really do is prefix any calls to the Woopsi gadgets with “WoopsiUI::” instead, or just include the bits of the namespace you want with “using WoopsiUI::SomeClass”, but if you’re just trying to get your application to compile again then using the entire namespace is a quick way to get things working.

I did this mainly so I could rename “WoopsiString” to “String”. Once I’d renamed the class everything broke, so I switched it back to “WoopsiString” again. Curses.