tom_usenet wrote in news:o8********************************@4ax.com in
comp.lang.c++:
//sample begin
namespace unique
{
}
using namespace unique;
namespace unique
{
class CInner;
}
class COuter
{
friend class CInner;
enum { ID = 5 };
};
namespace unique
{
class CInner
{
public:
CInner()
{
int i = COuter::ID;
}
};
} //!namespace
int main()
{
return 0;
}
Interestingly, Comeau fails to compile the above too, and I think this
is an EDG bug (that also causes the failure of the original code). The
friend declaration in COuter should find unique::CInner according to
the name lookup rules for elaborated-type-specifiers. However, Comeau
considers the friend declaration to refer to ::CInner. My analysis may
be flawed of course...
Seems right. Though ::CInner should refer to unique::CInner in
any case, so the friend declaration is unconditionaly inserting
a declaration for class CInner into ::.
The thread (
http://tinyurl.com/26dqo ) that I miss-remembered
contains this workaround (
http://tinyurl.com/2ams9 ):
//sample begin
#define unique
//namespace unique {} using namespace unique;
namespace unique
{
namespace foo
{
class CInner;
}
}
class COuter
{
friend class foo::CInner;
/* friend class ::CInner; doesn't work.
g++ 3.4 and VC++ 7.1 accept it.
*/
enum { ID = 5 };
};
namespace unique
{
namespace foo
{
class CInner
{
public:
CInner()
{
int i = COuter::ID;
}
};
}
} //!namespace
int main()
{
return 0;
}
Rob.
--
http://www.victim-prime.dsl.pipex.com/