Topic: using-declarations


Author: wmm@world.std.com ("William M. Miller")
Date: Fri, 16 May 2003 18:47:39 +0000 (UTC)
Raw View
""William Hayes"" <whayes@hfx.andara.com> wrote in message
news:xg6wa.56596$cB3.436613@nnrp1.uunet.ca...
> The Standard indicates that duplicate using declarations that refer to
> objects are not allowed in block scope (7.3.3, 8).  For example:
>
> int i = 0;
>
> namespace X
> {
>     int j = 1;
>     void f(){}
> }
>
> int main()
> {
>     extern int i;
>     extern int i;   // fine
>
>     using X::f;
>     using X::f;     // fine
>
>     using X::j;
>     using X::j; // error: "j" has already been declared in the current
scope
> }
>
> Multiple extern declarations of the global object i are allowed, multiple
> using declarations of function X::f are allowed, but multiple using
> declarations of object j are not allowed.  Why is this?
>
> My understand of using declarations is that they are not definitions, so
it
> seems that there should be no problem declaring the same object more than
> once.
>
> My broader problem, I think, is that I have been unable to find a detailed
> conceptual discussion of using declarations (or using directives, for that
> matter).

You're not alone in your confusion.  The Core Language WG
recognized long ago that there was something fishy about this
description; however, we've never managed to come to a consensus
on how to fix it.  See Core Language issue 36
(http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#36).

-- William M. Miller


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: whayes@hfx.andara.com ("William Hayes")
Date: Tue, 13 May 2003 15:11:16 +0000 (UTC)
Raw View
The Standard indicates that duplicate using declarations that refer to
objects are not allowed in block scope (7.3.3, 8).  For example:

int i = 0;

namespace X
{
    int j = 1;
    void f(){}
}

int main()
{
    extern int i;
    extern int i;   // fine

    using X::f;
    using X::f;     // fine

    using X::j;
    using X::j; // error: "j" has already been declared in the current scope
}

Multiple extern declarations of the global object i are allowed, multiple
using declarations of function X::f are allowed, but multiple using
declarations of object j are not allowed.  Why is this?

My understand of using declarations is that they are not definitions, so it
seems that there should be no problem declaring the same object more than
once.

My broader problem, I think, is that I have been unable to find a detailed
conceptual discussion of using declarations (or using directives, for that
matter).

Thanks.

___________________
William Hayes

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]