Namespaces and friends

Are there any special considerations when using friend functions and namespaces?

objid.h
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once

namespace FOO
{   typedef ULONG	objid_t;

   class OBJID
   {	FOO::objid_t		m_objnum;			

public:
        friend ostream & operator << (ostream & os, const FOO::OBJID & objid);
    };	//	end OBJID
};	//	end namespace 


objid.cpp
1
2
3
4
5
6
using namespace FOO;

ostream & operator << (ostream & os, const FOO::OBJID & objid) 
{   os << objid.m_objnum;
    return os;
}


My C++03 compiler is giving me the following error:

C:\dev\DATALIB\OBJID.cpp(42,14) : error (346) : member "FOO::OBJID::m_objnum" is inaccessible


Is this a compiler issue, or am I missing something here trying to use a friend function? If I don't put the OBJID class in a namespace, everything compiles fine.

And don't tell me to get a more recent compiler. C++03 is the latest compiler for the platform I work on.
If you don't specify the namespace of the friend function, it is declared in the namespace of the enclosing class(es).

http://ideone.com/Z4F0rM
Fun fact: line 21 uses ADL (argument-dependent lookup)
Last edited on
Thanks LB. That fixed the problem.
Topic archived. No new replies allowed.