Article ID: 192539
Article Last Modified on 10/7/2005
APPLIES TO
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
This article was previously published under Q192539
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
Case 2
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:
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 Visual Studio 6.0 service packs, what, where, why
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() { }
Keywords: kberrmsg kbbug kbfix kblangcpp kbqfe kbvs600sp3fix kbhotfixserver KB192539