Names namespace inside a .C file

Discussion in 'C++' started by qazmlp, Jul 22, 2003.

  1. qazmlp

    qazmlp Guest

    One of the implementation file(.C) file has the following code

    namespace Utils
    {
    // declaration & definition of some functions
    }


    Is this way having named namespace( inside a .C file instead of a .h)
    recommended for any case ?
     
    qazmlp, Jul 22, 2003
    #1
    1. Advertising

  2. (qazmlp) wrote in message news:<>...

    > One of the implementation file(.C) file has the following code
    >
    > namespace Utils
    > {
    > // declaration & definition of some functions
    > }


    If a function is both declared *and* defined in the source file, you
    should use an anonymous namespace instead:

    namespace {
    void f () { ... }
    }

    Namespaces are useful because they hide functions from the compiler
    until you tell the compiler where to find them. If a function's
    declaration is visible only in a single source file, then the function
    should be made invisible to all other source files. Anonymous
    namespaces effectively do just that.

    > Is this way having named namespace( inside a .C file instead of a .h)
    > recommended for any case ?


    I can't think of a good reason to have a *named* namespace for
    functions which, for all intents and purposes, do not exist outside
    of a single source file.

    - Shane
     
    Shane Beasley, Jul 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paddy McCarthy
    Replies:
    3
    Views:
    753
    Anthony J Bybell
    Sep 24, 2004
  2. Bob
    Replies:
    1
    Views:
    420
    Lucas Tam
    Jul 30, 2004
  3. Lewis G. Pringle, Jr.
    Replies:
    0
    Views:
    632
    Lewis G. Pringle, Jr.
    Sep 30, 2003
  4. fBechmann
    Replies:
    0
    Views:
    420
    fBechmann
    Jun 10, 2004
  5. Sfdesigner Sfdesigner
    Replies:
    5
    Views:
    186
    Chris Shea
    Aug 13, 2007
Loading...

Share This Page