Namespace best practice



  • Hi all,
    I'm going to refactor a few classes in my project to belong all to the same namespace. Each class has its own header and implementation file. I'm just curious to know which is the best practice to contain all of them in a single namespace, do I have to create a "namespace" file like:

    @
    namespace mySpace{
    class MyClassA;
    class MyClassB;
    }@

    or add the namespace block in each header file or what? Any suggestion is welcome.



  • Namespaces allows you to combine a set of similar classes (or not similar classes but library - remember namespace std) into one group.

    I think it's not very useful to put each class into separate namespace...

    Of course namespace can help you with potential ambiguity in different classes/files..



  • [quote author="AlekseyOk" date="1337850487"]
    I think it's not very useful to put each class into separate namespace...
    [/quote]

    I don't want to use a separate namespace for each class, I want to put all classes into a single namespace.



  • To add all classes into one namespace you should add

    @
    namespace youSpace
    {
    you_class_declaration and/or definition
    }
    @

    to each header and cpp file. Of course you can add

    @
    using namespace youSpace;
    @

    to cpp file.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.