DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 192539 - Last Review: October 7, 2005 - Revision: 3.2

Hotfix Download Available
View and request hotfix downloads
 
This article was previously published under Q192539

On This Page

SYMPTOMS

When a "using namespace std" directive is placed before a friend operator declaration, you may get one of the following two errors:

Case 1
error C2248: [member variable name] : cannot access private member declared in class [class name] [file name] (line number) : see declaration 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.

CAUSE

The friend operator resolution fails in the compiler front-end when std namespace is introduced.

RESOLUTION

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:
http://support.microsoft.com/contactus/?ws=support (http://support.microsoft.com/contactus/?ws=support)
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)
				

WORKAROUND

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.

STATUS

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  (http://support.microsoft.com/kb/194022/ ) Visual Studio 6.0 service packs, what, where, why
194295  (http://support.microsoft.com/kb/194295/ ) How to tell that a Visual Studio service pack is installed

MORE INFORMATION

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()
   { }
				

APPLIES TO
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kberrmsg kbbug kbfix kblangcpp kbqfe kbvs600sp3fix kbhotfixserver KB192539
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support