FIX: You receive error message when a "using namespace std" directive is placed before friend operator

This article was previously published under Q192539
This article has been archived. It is offered "as is" and will no longer be updated.
When a "using namespace std" directive is placed before a friend operatordeclaration, you may get one of the following two errors:

Case 1
error C2248: [member variable name] : cannot access private memberdeclared in class [class name] [file name] (line number) : seedeclaration of [member variable]
Case 2
[file name](line number) : fatal error C1001: INTERNAL COMPILER ERROR

(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information.

Error executing cl.exe.
The friend operator resolution fails in the compiler front-end when stdnamespace is introduced.
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Service Pack 3 for Visual Studio 6.0 that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.The English version of this fix should have the following file attributes or later:
   Date      Time      Size        File Name  Version#      Platform   -----------------------------------------------------------------   9/15/98   08:26p    1,183,795   C1xx.dll   12.00.8257.0  (x86)				
Do one of the following to work around this problem:
  • Move the "using namespace std" directive after the friend operator declaration.
  • Avoid using the "using namespace std" directive.
  • Forward declare the operator and/or class.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.This bug was corrected in Visual Studio 6.0 Service Pack 3.

For more information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:
194022 Visual Studio 6.0 service packs, what, where, why
194295 How to tell that a Visual Studio service pack is installed

Test1.cpp reproduces the C2248 error in case 1

   // test1.cpp   // Compiler options needed: cl /c /GX   #include <iostream>   using namespace std;   #ifdef WORKAROUND   class CMyClass;   ostream& operator <<(ostream &, const CMyClass &);   #endif // WORKAROUND   class CMyClass   {   public:     friend ostream& operator <<(ostream &, const CMyClass &);     // An alternative workaround is to define the operator in the     // class declaration. In this case it is not necessary to forward     // declare the class and friend function.   private:      int value;   };   ostream& operator <<(ostream& out, const CMyClass& m)   {      int i = m.value;  // C2248 Error      return out;   }   void main()   { }				

Test2.cpp reproduces the C1001 error in case 2

   // test2.cpp   // Compiler options needed: cl /c /GX   #include <iostream>   using namespace std;   #ifdef WORKAROUND   int operator+(int, const class &);   #endif // WORKAROUND   class CMyClass   {   public:     friend int operator+(int, const CMyClass &);  // C1001 Error.   };   void main()   { }				

Article ID: 192539 - Last Review: 12/05/2015 09:16:10 - Revision: 3.2

Microsoft Visual C++ 6.0 Enterprise Edition, Microsoft Visual C++ 6.0 Professional Edition, Microsoft Visual C++, 32-bit Learning Edition 6.0

  • kbnosurvey kbarchive kberrmsg kbbug kbfix kblangcpp kbqfe kbvs600sp3fix kbhotfixserver KB192539