namespace and visibility

Does using a namespace affect the visibility of functions?

1
2
3
4
5
6
7
8
9
10
11
namespace DDL 
{
class DDLTYP 
{
private:
	void Format (ostream & os) const;

public:
	friend ostream & operator << (ostream & os, const DDLTYP & typ);
};
};


The following code generates a compile error when using a namespace.
C:\DEV\DDLDLL\DDLTYP.cpp(97,6) : error (346) : function "DDL::DDLTYP::Format" is inaccessible
1
2
3
4
5
using namespace DDL;
ostream & operator << (ostream & os, const DDL::DDLTYP & typ)
{	typ.Format (os);
	return os;
}


Since operator << is declared as a friend, shouldn't it be able to see Format()? It does indeed see Format() if namespace is not used. Yet when declaring DDLTYP within namespace DDL, Format() becomes inaccessible. If I move Format() to public, it compiles. Why should the use of a namespace make a difference to the visibility of Format() assuming references are properly qualified with the DDL scope?
Try defining the operator overload function inside the DDL namespace.
Topic archived. No new replies allowed.