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. Advertisements

  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. Advertisements

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. Razmig K
    Replies:
    3
    Views:
    842
    John L Fjellstad
    Sep 5, 2003
  2. Jordi Vilar
    Replies:
    5
    Views:
    2,488
    Jonathan Turkanis
    Feb 18, 2004
  3. Insert Pseudonym Here

    using-declaration vs. using-directive

    Insert Pseudonym Here, May 3, 2004, in forum: C++
    Replies:
    1
    Views:
    1,848
    Rob Williscroft
    May 3, 2004
  4. marco_segurini
    Replies:
    4
    Views:
    1,146
    Rob Williscroft
    Jun 16, 2004
  5. marco_segurini

    unnamed namespace and friend

    marco_segurini, Feb 3, 2005, in forum: C++
    Replies:
    1
    Views:
    468
    msalters
    Feb 3, 2005
  6. Marco Jez

    unnamed namespace collision

    Marco Jez, Mar 28, 2005, in forum: C++
    Replies:
    1
    Views:
    527
    Peter MacMillan
    Mar 28, 2005
  7. Jordi Vilar
    Replies:
    5
    Views:
    18,851
    Jonathan Turkanis
    Feb 18, 2004
  8. Ehud Shapira
    Replies:
    20
    Views:
    1,561
    Ehud Shapira
    Jun 30, 2007
Loading...