Thread: Help with namespaces

  1. #1
    Caution: Wet Floor
    Join Date
    May 2006
    Posts
    55

    Help with namespaces

    Is this a good way to use a namespace?

    Code:
    #include <iostream>
    
    namespace Hw { void hello(); }
    void Hw::hello() { using namespace std; cout << "Hello, world.\n"; }
    
    int main() { Hw::hello();}

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I don't see a problem with it. Real world examples are more complex and have different criteria for how you want to do things. I prefer to always explicitly specify the std namespace, but putting the using directive inside the function is almost always fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. namespaces or static classes ?? you decide
    By Hussain Hani in forum C++ Programming
    Replies: 9
    Last Post: 07-11-2009, 11:20 AM
  2. need help wiht using classes...namespaces...
    By hockey97 in forum C++ Programming
    Replies: 9
    Last Post: 09-02-2008, 02:22 PM
  3. C and namespaces
    By oyse in forum C Programming
    Replies: 2
    Last Post: 05-05-2004, 09:39 AM
  4. namespaces and friends
    By okinrus in forum C++ Programming
    Replies: 1
    Last Post: 03-27-2004, 08:47 AM
  5. custom namespaces
    By uvacow in forum C# Programming
    Replies: 2
    Last Post: 03-16-2004, 02:53 PM