home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,767 of 33,346   
   DeMarcus to All   
   How do you define a namespace?   
   28 Dec 12 06:40:36   
   
   From: use_my_alias_here_at_hotmail_com@tellus.orb.dotsrc.org   
      
   Hi,   
      
   I have no question about the namespace in the header file, so for this   
   post we declare it like this.   
      
   // MyClass.hpp   
   #pragma once   
      
   namespace MyProduct   
   {   
   class MyClass   
   {   
   public:   
        void myMethod();   
   };   
   }   
      
      
   Now, for the source file I've seen at least three variants.   
      
   A)   
   // MyClass.cpp   
   #include "MyClass.hpp"   
      
   namespace MyProduct   
   {   
   void MyClass::myMethod()   
   {   
        // ...   
   }   
   }   
      
      
   B)   
   // MyClass.cpp   
   #include "MyClass.hpp"   
      
   void MyProduct::MyClass::myMethod()   
   {   
        // ...   
   }   
      
      
   C)   
   // MyClass.cpp   
   #include "MyClass.hpp"   
      
   using namespace MyProduct;   
      
   void MyClass::myMethod()   
   {   
        // ...   
   }   
      
      
   Are there more variants?   
   What are the pros and cons with these?   
      
      
   Thanks,   
   Daniel   
      
      
   PS. It's striking how little information there is about this topic. I   
   would hope we can come up with a good summary to be put on C++ FAQ   
   Lite.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca