Using-declaration or using-directive inside unnamed-namespace?

Discussion in 'C++' started by Niels Dekker - no reply address, Apr 27, 2010.

  1. We have some using-declarations and using-directives at file scope (in a CPP
    file, right after the #include statements). Does it matter much if they are
    places in an unnamed namespace instead? I mean, does it make any difference
    (file scope versus unnamed-namespace)?

    For example:

    #include "my_things.h"
    #include <memory>

    namespace // unnamed
    {
    using ::std::tr1::shared_ptr;
    using namespace my_things;
    }

    // Using shared_ptr and things from my_things here...


    Kind regards,

    Niels

    --
    Niels Dekker
    http://www.xs4all.nl/~nd/dekkerware
    Scientific programmer at LKEB, Leiden University Medical Center
    Niels Dekker - no reply address, Apr 27, 2010
    #1
    1. Advertising

  2. >> We have some using-declarations and using-directives at file scope
    >> (in a CPP file, right after the #include statements). Does it matter
    >> much if they are places in an unnamed namespace instead?


    Victor Bazarov wrote:
    > The using declarations and using-directives only have effect for this
    > particular translation unit. They don't create additional symbols
    > that might become visible from another module, if that's what you're
    > worrying about.


    Thanks, Victor. So it doesn't really matter whether they are inside an
    unnamed namespace or at file scope.

    I thought so already, but I wanted to be sure :)

    Kind regards,

    Niels

    --
    Niels Dekker
    http://www.xs4all.nl/~nd/dekkerware
    Scientific programmer at LKEB, Leiden University Medical Center
    Niels Dekker - no reply address, Apr 27, 2010
    #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. Jordi Vilar
    Replies:
    5
    Views:
    2,281
    Jonathan Turkanis
    Feb 18, 2004
  2. marco_segurini
    Replies:
    4
    Views:
    1,002
    Rob Williscroft
    Jun 16, 2004
  3. Jordi Vilar
    Replies:
    5
    Views:
    17,828
    Jonathan Turkanis
    Feb 18, 2004
  4. Ehud Shapira
    Replies:
    20
    Views:
    1,118
    Ehud Shapira
    Jun 30, 2007
  5. Stefan Ram
    Replies:
    0
    Views:
    69
    Stefan Ram
    Apr 18, 2014
Loading...

Share This Page