Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

friend & namespace & transla - Macbeth (轉載)

0 views
Skip to first unread message

Myth

unread,
Jul 7, 1999, 3:00:00 AM7/7/99
to
[1;37m【 以下文字轉載自 [32mjunk [37m討論區 】
【 原文由 [32m Macbeth [37m 所發表 】 [m

VC 6.0 有個 bug 就是 friend function 的實作跟宣告分開時就會有問題

就如同你上面用的一樣

你試看看 apply SP3 之後還會不會


BUG: 'using namespace std' Before Friend Operator Fails Compile
Last reviewed: October 29, 1998
Article ID: Q192539

Frmo Microsoft Knowledge Base


The information in this article applies to:
Microsoft Visual C++, 32-bit Editions, version 6.0

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 fix that corrects this problem is now available from Microsoft,
but it has not been fully regression tested and should be applied only to
systems experiencing this specific problem. If you are not severely affected
by this specific problem, use the workarounds described in this article.

To resolve this problem immediately, contact Microsoft Product Support
Services to obtain the fix. For a complete list of Microsoft Product
Support Services phone numbers and information on support costs, please
go to the following address on the World Wide Web:

http://support.microsoft.com/support/supportnet/default.asp

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)

NOTE: If you contact Microsoft to obtain this fix, a fee may be charged. This
fee is refundable if it is determined that you only require the fix you
requested. However, this fee is non-refundable if you request additional
technical support.
For more information about eligibility for no-charge technical support, see
the following article in the Microsoft Knowledge Base:


ARTICLE-ID: Q154871
TITLE : Determining If Your Product Is Eligible for No-Charge
Technical Support


Workaround
Use one of the following three possible workarounds:

- 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 this to be a bug in the Microsoft products listed
at the beginning of this article.

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


--
[;33;45m◣ [1;31m., [33m tc070022.seeder.net [37m 所發表之文章 [m
[;33;45m█◣ [1;31m-●- [33m◢█◣ [32m/" [37m‧ [36m國立中央大學 資訊管理研究所 [m
[;31;44m == [1;33m◢████◣ [37m‧ [32m破曉時刻 sunrise.twbbs.org [m

0 new messages