Topic: using namespace std;' and 'friend operator+' have problems in vc++6.0


Author: psoares@ip.pt (Paulo Soares)
Date: 1998/09/22
Raw View
I recently upgraded from Microsoft Visual C++ 5.0 to 6.0 and the
result was the manifestation of an error that didn't exist before.
The code is as follows (it does nothing, it's just an example):

#include <vector>
using namespace std;

class MyClass
{
public:
   MyClass( int i );
   friend MyClass operator+(const MyClass& first, const MyClass&
second );
protected:
   int my_data;
};

MyClass::MyClass(int i)
{
    my_data = i;
}

MyClass operator+( const MyClass& first, const MyClass& second )
{
   return MyClass( first.my_data + second.my_data);
}

The compiler says that it cannot access the protected members in
operator+. If I remove 'using namespace std;' it works as expected.
Is it using some templated operator+ hidden in the namespace std?
I'm curious.

Best Regards
Paulo Soares
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Michael V. Leonov" <leonov@propro.ru>
Date: 1998/09/23
Raw View
Paulo Soares wrote in message <36077088.3062578@news.ip.pt>...
>I recently upgraded from Microsoft Visual C++ 5.0 to 6.0 and the
>result was the manifestation of an error that didn't exist before.
<snipped>
>The compiler says that it cannot access the protected members in
>operator+. If I remove 'using namespace std;' it works as expected.
>Is it using some templated operator+ hidden in the namespace std?
>I'm curious.

Dear Paulo,
this is a known bug in MSVC 6.0, see Visual C++ support page for details.
Best regards,
Michael V. Leonov
leonov@propro.ru
http://propro.ru/leonov




[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]