Topic: Interesting problem with namespaces


Author: "Andrey I. Savov" <andrey@ix.netcom.com>
Date: 1997/02/04
Raw View
Hello guys,

I ran into an interesting problem using namespaces in C++. The following
usage of namespaces appear to be correct (at least I haven't been able to
disprove this) as far as the language constructs go, however, it creates
problems in Microsoft C++ compiler.

class A
   {
   public:
   int         a;

   typedef class A B;

   static int tdesc;
   };

namespace
   {
   using A::B;

   int B::tdesc = 56;
   };

The problem appears to be in using scope resolution operator with
typedef-ed scope name inside a namespace.

Can you please tell me:

1. Is this construct legal to use
2. Has anyone ever seen problems with such uses of namespaces in other C++
compilers

Thanks in advance,
Andrey
Object Dynamics Corp.
(andrey@odcnet.com)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Larry Brasfield" <SpamGuard_LarryBr@microsoft.com>
Date: 1997/02/06
Raw View
Andrey I. Savov <andrey@ix.netcom.com> wrote in article
<01bc1209$8e989060$6be15dcf@207.93.225.107>...
> Hello guys,
>
> I ran into an interesting problem using namespaces in C++. The
following
> usage of namespaces appear to be correct (at least I haven't been
able to
> disprove this) as far as the language constructs go, however, it
creates
> problems in Microsoft C++ compiler.

I believe your usage of namespaces is incorrect, as
explained below.  However, I have seen a KB article
describing an erroneous conflict involving typedef'ed
names in different namespaces.  And after adding the
below corrections, MSVC 4.2 croaks on this.

MSVC 5.0 (an announced but not yet released
product) complains about your code, saying:
 error C2888: 'int A::tdesc' : symbol cannot be
  defined within namespace '`anonymous-namespace'',
whereas it compiles the following without error.

namespace {  // make promise agree with action
> class A
>    {
>    public:
>    int         a;
>
// Here, you promise to define A::tdesc in global namespace.
>    typedef class A B;
>
>    static int tdesc;
>    };
>
> namespace
>    {
>    using A::B;
>
// Here, you attempt to define ::A::tdesc in anonymous namespace.
>    int B::tdesc = 56;
>    };
>
> The problem appears to be in using scope resolution operator with
> typedef-ed scope name inside a namespace.
>
> Can you please tell me:
>
> 1. Is this construct legal to use
No.

> 2. Has anyone ever seen problems with such uses of namespaces
>  in other C++ compilers
I should hope so.

> Thanks in advance,
> Andrey
> Object Dynamics Corp.
> (andrey@odcnet.com)
--
Larry Brasfield

The opinions expressed herein are mine, and are not
intended to reflect the views of any other entity.
(For an e-mail reply, remove "SpamGuard_".)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]