473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GNU C: Namespace resolution operator on friend declarations problem

I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado
2.11 environment.

I tried the following construct:

void foo();

namespace N
{

class C
{
friend void ::foo();
};

}

GCC does not accept namespace resolution in the friend function declaration.
MS Visual C compiler is happy with it, though.

ANSI C++ standard allows fully qualified name in friend declaration when
referring to a member function of another class, but doesn't say anything
about referring to a nonmember function from another namespace. I believe
it's just oversight, because there doesn't seem any syntactic and semantic
ambiguity with that.
Jul 19 '05 #1
6 4240

"Alexander Grigoriev" <al***@earthlink.net> wrote in message
news:UO*****************@newsread3.news.pas.earthl ink.net...
I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado 2.11 environment.

I tried the following construct:

void foo();

namespace N
{

class C
{
friend void ::foo();
};

}

GCC does not accept namespace resolution in the friend function declaration. MS Visual C compiler is happy with it, though.

I would put my trust with MS VC++ compiler here..even though can't quote
from the standard right away ;-).

--
J.Schafer
Jul 19 '05 #2
On Thu, 11 Sep 2003 14:39:48 GMT, "Alexander Grigoriev"
<al***@earthlink.net> wrote:
I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado
2.11 environment.

I tried the following construct:

void foo();

namespace N
{

class C
{
friend void ::foo();
};

}

GCC does not accept namespace resolution in the friend function declaration.
MS Visual C compiler is happy with it, though.

ANSI C++ standard allows fully qualified name in friend declaration when
referring to a member function of another class, but doesn't say anything
about referring to a nonmember function from another namespace.
It does - a friend function declaration can use a qualified name.

I believeit's just oversight, because there doesn't seem any syntactic and semantic
ambiguity with that.


The code is perfectly standard. You must have an old version of gcc,
since 3.2 compiles it fine.

Tom
Jul 19 '05 #3
I'd suspect the compiler in question has relied too much on the standard
text. Since the standard doesn't mention friends from other namespaces (only
from other classes), the developpers decided that it's not allowed. I'd
consider such omission in the standard text a defect.

"tom_usenet" <to********@hotmail.com> wrote in message
news:dj********************************@4ax.com...
On Thu, 11 Sep 2003 14:39:48 GMT, "Alexander Grigoriev"
<al***@earthlink.net> wrote:
I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado2.11 environment.

I tried the following construct:

void foo();

namespace N
{

class C
{
friend void ::foo();
};

}

GCC does not accept namespace resolution in the friend function declaration.MS Visual C compiler is happy with it, though.

ANSI C++ standard allows fully qualified name in friend declaration when
referring to a member function of another class, but doesn't say anything
about referring to a nonmember function from another namespace.


It does - a friend function declaration can use a qualified name.

I believe
it's just oversight, because there doesn't seem any syntactic and semanticambiguity with that.


The code is perfectly standard. You must have an old version of gcc,
since 3.2 compiles it fine.

Tom

Jul 19 '05 #4
I also use GNU C++ for VxWorks on a pentium architect. If your using GCC
2.7.2, as I am, I do believe this version does not completely support
namespaces.

"Alexander Grigoriev" <al***@earthlink.net> wrote in message
news:UO*****************@newsread3.news.pas.earthl ink.net...
I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado 2.11 environment.

I tried the following construct:

void foo();

namespace N
{

class C
{
friend void ::foo();
};

}

GCC does not accept namespace resolution in the friend function declaration. MS Visual C compiler is happy with it, though.

ANSI C++ standard allows fully qualified name in friend declaration when
referring to a member function of another class, but doesn't say anything
about referring to a nonmember function from another namespace. I believe
it's just oversight, because there doesn't seem any syntactic and semantic
ambiguity with that.

Jul 19 '05 #5
On Fri, 12 Sep 2003 02:51:59 GMT, "Alexander Grigoriev"
<al***@earthlink.net> wrote:
I'd suspect the compiler in question has relied too much on the standard
text. Since the standard doesn't mention friends from other namespaces (only
from other classes), the developpers decided that it's not allowed. I'd
consider such omission in the standard text a defect.


You'll have to explain why you think that the standard makes this
illegal:

namespace A
{
void foo();
}

class Bar
{
friend void A::foo();
};

8.3/1 explicitly allows a friend function declaration to name a
qualified-id (like A::foo).

Tom
Jul 19 '05 #6
Alexander Grigoriev wrote:
Now I see: "or the declaration of a friend function that is a member of
another class or namespace"


Please don't top-post. Read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #7

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

Similar topics

2
by: Xavier Decoret | last post by:
The following code does not compoile with gcc-3.2.3 namespace dummy { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Interface of Foo...
10
by: Francesco Gallarotti | last post by:
Can any of you help with this? Pretty much all the errors I have belong to 2 different categories: 1) error C2872: ambiguous symbols 2) error C2662: cannot convert 'this' pointer from 'const class...
2
by: Tim Partridge | last post by:
I'm not very good with namespaces, so my problem is probably a simple one. I can't get the following to compile on gcc 3.3.1. It reports main.cc: In function 'std::ostream &...
1
by: JustSomeGuy | last post by:
I am writing classes and I want them to belong to mynamespace What is the syntax to say that the class I'm defining is a member of mynamespace? What is the scope of the syntax and how does one...
8
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
5
by: Teddy | last post by:
Hello all consider the class Date declaretion below: class Date { public: Date(); Date(int year, int month, int day); Date(const string&); int getYear() const;
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
3
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<'...
2
by: Layton | last post by:
Hi, CPP gurus, How to use friend function cross the namespace? I have the following sample code with operator << overloaded, it's working. The problem the operator << function can't access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...

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.