473,396 Members | 1,853 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.

using declaration

Hi,

Should the below code compile according to C++ standard?

namespace N { struct S{ }; }
void S() { }
using N::S;

It seems that various compilers behave differently with it. I found the
example on MS newsgroup.

Best regards,
Marcin

Jul 22 '05 #1
4 1790

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
Hi,

Should the below code compile according to C++ standard?

namespace N { struct S{ }; }
void S() { }
using N::S;


IMO, no.
3.4.3.2/5 reads -
<quote>
During the lookup of a qualified namespace member name, if the lookup finds more
than one declaration of the member, and if one declaration introduces a class
name or enumeration name and the other declarations either introduce the same
object, the same enumerator or a set of functions, the non-type name hides the
class or enumeration name if and only if the declarations are from the same
namespace; otherwise (the declarations are from different namespaces), the
program is ill-formed
</quote>

void S() belongs to global namespace while struct S belongs to N. Hence I see
the program as illegal.

-Sharad


Jul 22 '05 #2
Użytkownik "Sharad Kala" <no*****************@yahoo.com> napisał w
wiadomości news:2h************@uni-berlin.de...

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
Hi,

Should the below code compile according to C++ standard?

namespace N { struct S{ }; }
void S() { }
using N::S;
IMO, no.
3.4.3.2/5 reads -
<quote>
During the lookup of a qualified namespace member name, if the lookup

finds more than one declaration of the member, and if one declaration introduces a class name or enumeration name and the other declarations either introduce the same object, the same enumerator or a set of functions, the non-type name hides the class or enumeration name if and only if the declarations are from the same namespace; otherwise (the declarations are from different namespaces), the
program is ill-formed
</quote>


Right, but standard says 'during lookup'. If S is never used, the lookup is
not performed (am I right?).

Best regards,
Marcin
Jul 22 '05 #3
Marcin Kalicinski posted:
Użytkownik "Sharad Kala" <no*****************@yahoo.com> napisał w
wiadomości news:2h************@uni-berlin.de...

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
> Hi,
>
> Should the below code compile according to C++ standard?
>
> namespace N { struct S{ }; }
> void S() { }
> using N::S;


IMO, no.
3.4.3.2/5 reads -
<quote>
During the lookup of a qualified namespace member name, if the lookup
finds more than one declaration of the member, and if one declaration
introduces a class name or enumeration name and the other declarations
either introduce the same object, the same enumerator or a set of
functions, the non-type name hides the class or enumeration name if
and only if the declarations are from the same namespace; otherwise
(the declarations are from different namespaces), the program is
ill-formed </quote>


Right, but standard says 'during lookup'. If S is never used, the
lookup is not performed (am I right?).

Best regards,
Marcin


DEBATE DEBATE DEBATE
-JKop
Jul 22 '05 #4

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
Użytkownik "Sharad Kala" <no*****************@yahoo.com> napisał w
wiadomości news:2h************@uni-berlin.de...
[snip] Right, but standard says 'during lookup'. If S is never used, the lookup is
not performed (am I right?).


Well Comeau online thinks the code is fine while VC++ 7.1 and g++ 3.3.1 don't
think so.
The example in the standard indeed refers to a case where the name is used in
the program. So if S is used in the program then it's not legal, not sure if
it's not used.

-Sharad
Jul 22 '05 #5

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

Similar topics

1
by: Ken Larson | last post by:
I have a question about using XSL to extract information from an SVG (XML) file that has a DOCTYPE/DTD declaration. I am able to do this successfully if I write my own SVG files without such a...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
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:...
5
by: John Gabriele | last post by:
I'm hoping someone can please help me remember the C++ rule: When you're writing a header file for a class (say, some_namespace::Bar), and that class makes use of another class...
3
by: Dan | last post by:
Is there a better way to include the XML declaration than the following? XmlDeclaration dec =m_XMLDocument.CreateXmlDeclaration("1.0",string.Empty, "yes");...
3
by: pyramus | last post by:
I am wondering which one should be preferred for creating a local synonym within a function definition. Let's say I have a type in my library called MyLib::Foundation::int32, which I can't stand...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
0
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
7
by: =?Utf-8?B?QmVu?= | last post by:
Hi, I sometimes see code where the 'using' statements at the top of the file are located before the namespace declaration, and sometimes they are located inside it. For example: using...
6
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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
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.