[PyKDE] namespaces in sip

Jim Bublitz jbublitz at nwinternet.com
Thu Oct 16 18:11:01 BST 2003


On Wednesday October 15 2003 16:26, Patrick Stinson wrote:
> ...and now if we have something like
>
> namespace PK
> {
> class Port
> {
>   enum Type
>   {
>     Input,
>     Output
>   };
>   PK_Port(PK_Port::Type);
> };
>
> };
>
> we should get an error because of the nested [enum], correct?
> hope not...

PK::Port::Type - otherwise it should work.

PK_Port is only a (unqualified) method name. If you meant PK_Port 
to be the ctor for class Port, it should be:

namespace PK
{
  class Port
   {
       enum Type
      {
         Input,
         Output
       };

      Port(PK::Port::Type);
   };
};

The class name (in the 'class' statement), the ctor *name* and 
dtor *name* don't get qualified - everything else does 
("everything else" is a *reference* to the name, not a 
definition of the name). Same with the enum name - no 
qualification when it's declared, but qualified wherever it's 
referenced.

Here's an analogy that might help. Imagine a filesystem tree 
like:

PK
 |_Port
         |_Type

None of those is qualified. But if I want a file somewhere in 
'Type', I need to do /PK/Port/Type/file - sip doesn't have a 
concept for namespaces like a file system's './' or '../'  or 
'current directory' and always needs the full 'path' to an 
object to find it (but not to define it).

The underscore ("_") naming is a sip convention for generated 
code (if that's where it came from), but syntactically it 
doesn't mean anything except "here's a name that I gave a prefix 
to". You're actually writing C++ syntax - you just don't get to 
leave things out for sip like you do for C++.

Jim




More information about the PyQt mailing list