Help with namespaces

This is a discussion on Help with namespaces within the C++ Programming forums, part of the General Programming Boards category; Is this a good way to use a namespace? Code: #include <iostream> namespace Hw { void hello(); } void Hw::hello() ...

  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,325
    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, 07:47 AM
  5. custom namespaces
    By uvacow in forum C# Programming
    Replies: 2
    Last Post: 03-16-2004, 01:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21