473,466 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unnamed namespace and friend

Hi,

I like to know if this code is legal:

namespace
{
void unnamed_ns(){}
}

class test
{
friend void unnamed_ns();
};

int main()
{
unnamed_ns();
}

because the c++ compiler of vs2003 return me this error

error C2668: 'unnamed_ns' : ambiguous call to overloaded function
could be 'void unnamed_ns(void)'
or 'void `anonymous-namespace'::unnamed_ns(void)'

while all is fine for Comeau Online

Thanks a lot.
Marco.
Jul 23 '05 #1
1 1618

marco_segurini wrote:
Hi,

I like to know if this code is legal:

namespace { void unnamed_ns(){} }

class test {friend void unnamed_ns(); };

int main() {
unnamed_ns();
}


Yes. The friend declaration refers to a name that can be found
in the enclosing scope (in this case, global) because an unnamed
namespace implies a using directive. (7.3.1.1)

Regards,
Michiel Salters

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anthony | last post by:
Hello, I have been reading up on unnamed namespaces in the context of hiding classes as mentionned by the GOF Facade pattern description. I was hoping someone could shed some light on this. I...
4
by: marco_segurini | last post by:
Hi, the following test program shows a solution to a problem I have had. Now, this test program is compiled and linked by VS2003 and g++ while Comeau-on-line-compiler fails with this messages:...
1
by: Marco Jez | last post by:
What are the requirements imposed by the Standard on unnamed namespaces? I mean, is the hidden name guaranteed to be unique across multiple translation units, or only within the declaring...
3
by: Sandy | last post by:
Hi, I have two files as folllows file1.cpp #include<iostream> using namespace std; namespace { void show(); void fun() { cout<<"fun called\n"; } }
2
by: dioscuroi | last post by:
Is there any difference between declaring in unnamed namespace and i global namespace? I can't recognize this p.s: Have a nice day ^_________ -
9
by: Ivan Mascovich | last post by:
Previous posts (and compilers) confirm that class X { friend void Y() ; } ; does not match namespace
3
by: Tomás | last post by:
I have a header file/source file combo. There's approximately five functions in the source file. Only one of the functions should be used by other translation units, so I've defined the other...
1
by: vsgdp | last post by:
I just want to clarify: Say I have a helper class that is only used in one translation file (e.g., a predicate class). I don't want the name of this class to conflict with other class names in...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.