Topic: Collision between the name of class and name of parameter from different namespace


Author: Steve Clamage <clamage@eng.sun.com>
Date: Thu, 9 Aug 2001 22:50:12 GMT
Raw View
On Thu, 9 Aug 2001, Sergey Shabalov wrote:

> namespace A
> {
>     class cA
>     {
>         class Init
>         {
>         };
>     };
> }
>
> namespace B
> {
>     class cB_1
>     {
>         void Init(){};
>     };
>     class cB_2
>     {
>         void Init(){};
>     };
>
>     class cB_3: cB_1, cB_2
>     {
>
>         class cBB
>         {
>             cBB( const cBB & Init ){};
>     // error C2385: 'cB_3::Init' is ambiguous
>     // warning C4385: could be the 'Init' in base 'cB_1' of class 'cB_3'
>     // warning C4385: or the 'Init' in base 'cB_2' of class 'cB_3'
>
>         };
>     };
> }
>
> If I rename the nested class Init in namespace A then all are Ok.
> But I can not understand what it is. Is it a bug of my compiler or bug in my
> brain?

Assuming this is the exact code that you compiled, the compiler is
very confused. The contents of namespace A are not referred to
anywhere in namespace B, and A::cA::Init is not visible anywhere
in namespace B.

The code above is valid. The Init on the line with the error message
is the name of a constructor parameter, and cannot possibly be
ambiguous in any case.

A reference to Init() in a member function of class cBB would be
ambiguous, because there is no way to choose between cB_1::Init
and cB_2::Init. You would need to qualify the referece.

---
Steve Clamage, stephen.clamage@sun.com

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: "Sergey Shabalov" <Shabalov_S_V@confectionery.com.ua>
Date: Thu, 9 Aug 2001 00:11:54 GMT
Raw View
I have written a pice of code and get error message.

namespace A
{
    class cA
    {
        class Init
        {
        };
    };
}

namespace B
{
    class cB_1
    {
        void Init(){};
    };
    class cB_2
    {
        void Init(){};
    };

    class cB_3: cB_1, cB_2
    {

        class cBB
        {
            cBB( const cBB & Init ){};  // error C2385: 'cB_3::Init' is
ambiguous
                                        // warning C4385: could be the
'Init' in base 'cB_1' of class 'cB_3'
                                        // warning C4385: or the 'Init' in
base 'cB_2' of class 'cB_3'

        };
    };
}

If I rename the nested class Init in namespace A then all are Ok.
But I can not understand what it is. Is it a bug of my compiler or bug in my
brain?
What say the standart about this problem?

I use VC++ v6

Best Regards,
Sergey




---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: "Serge Smeesters" <sergesmeesters@netcourrier.com>
Date: Thu, 9 Aug 2001 18:25:23 GMT
Raw View
> I have written a pice of code and get error message.
>
>    namespace A
>    {
>        class cA
>        {
>            class Init
>            {
>            };
>        };
>    }
>
>    namespace B
>    {
>        class cB_1
>        {
>            void Init(){};
>        };
>
>        class cB_2
>        {
>            void Init(){};
>        };
>
>        class cB_3: cB_1, cB_2
>        {
>
>            class cBB
>            {
>                cBB( const cBB & Init ){};  // error C2385:
>            };
>        };
>    }
>
>    error :'cB_3::Init' is ambiguous
>    warning C4385: could be the 'Init' in base 'cB_1' of class 'cB_3'
>    warning C4385: or the 'Init' in base 'cB_2' of class 'cB_3'

compiler bug.

Init is here the name of an function argument, no problem even if hiding otherthing.

> If I rename the nested class Init in namespace A then all are Ok.

Bug imply often a impenetrable behavior...

> But I can not understand what it is.
> Is it a bug of my compiler or bug in my brain?
> What say the standart about this problem?
>
> I use VC++ v6

It's a compiler bug.

Normaly, you should write a horrible code like :

   class Init
   {
     public:
       Init( int Init ) :m_i(Init) {}
     private:
       int m_i;
   };

   Init f( int Init )
   {
      return ::Init( Init );
   }

   int main()
   {}

... but it's not realy elegant !

Maybe the bug is a Microsoft elegance establishment extention ;-))

--
Serge Smeesters
http://www.sesa.ucl.ac.be/serge/



---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Thu, 9 Aug 2001 18:25:48 GMT
Raw View
In article <3b713d3e@digi8.pi.net.ua>, Sergey Shabalov <Shabalov_S_V@con
fectionery.com.ua> writes
>I have written a pice of code and get error message.
>
>namespace A
>{
>    class cA
>    {
>        class Init
>        {
>        };
>    };
>}
As there are no using decls, directives etc. the above has (or should
have) nothing to do with the problem.

>
>namespace B
>{
>    class cB_1
>    {
>        void Init(){};
>    };
>    class cB_2
>    {
>        void Init(){};
>    };
>
>    class cB_3: cB_1, cB_2
Did you intend private inheritance?

>    {
>
>        class cBB
>        {
>            cBB( const cBB & Init ){};
Now Init is the name of a parameter which should hide the function
names.

> // error C2385: 'cB_3::Init' is
>ambiguous
>                                        // warning C4385: could be the
>'Init' in base 'cB_1' of class 'cB_3'
>                                        // warning C4385: or the 'Init' in
>base 'cB_2' of class 'cB_3'
But apparently the compiler does not think so. I seem to remember that
there are some very hairy scoping issues in reusing a member name as a
parameter name. Here it is even worse, because the parameter name is the
name of two inherited members of an enclosing class. I am not surprised
that a compiler gets confused. Actually, pragmatically, I am happy to
let the compiler call me an error here (even if it should not:) because
I can easily fix the problem by changing the parameter name.
>
>        };
>    };
>}
>
>If I rename the nested class Init in namespace A then all are Ok.

I think that is just an artefact of the confusion the compiler is
feeling (it has got so many different Inits into it lookup tables that
it does not know its ???? from its elbow:)

>But I can not understand what it is. Is it a bug of my compiler or bug in my
>brain?
Probably the former, but why did you want to write such confusing code?

>What say the standart about this problem?

That the compiler is mistaken.

However almost any coding guidelines would also suggest that you are
misguided.

>

Francis Glassborow      ACCU
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: Thu, 9 Aug 2001 18:26:50 GMT
Raw View
"Sergey Shabalov" <Shabalov_S_V@confectionery.com.ua> writes:

> But I can not understand what it is. Is it a bug of my compiler or
> bug in my brain?

It's a bug in the compiler. Init is a parameter name here, not the
name of a function.

Regards,
Martin

---
[ 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.research.att.com/~austern/csc/faq.html                ]