473,811 Members | 4,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing namespaces

Forgive me for asking so many questions so quickly. I am simply
asking as they come up unanswered in my book.

Can you change namespaces half way through a file? For instance, if
you want to use std and then half way through switch to your own:
{
...
using namespace std;
cout << "doing polygons";
using namespace polygon;
cout << poly1;
...
}

I know that this is a ridiculous example. Why would anyone define an
outstream for a 3D object with the name cout. But, suppose they did,
would this code snippet work, or do you have to use just one namespace
per file and be explicit about the use of other namespaces?
Jul 22 '05
21 1898

"Andre Kostur" <nn******@kostu r.net> wrote in message
news:Xn******** *************** ********@207.35 .177.134...
"Sharad Kala" <no************ ******@yahoo.co m> wrote in
news:2l******** ****@uni-berlin.de:

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:opsas0q1jt 212331@andronic us...
On Thu, 08 Jul 2004 05:32:45 GMT, Russell Hanneken <me@privacy.net >
wrote:

> John Harrison wrote:
>> On Wed, 07 Jul 2004 22:20:42 GMT, Russell Hanneken
>> <me@privacy.net >

[snip]

I think I'm really going to have to look this up in the standard,
which is always a scary prospect. But here's a guess, your version of
the code injects all the std namespace names into the scope of main,
but ::string ignores any names within the scope of main and just
looks directly at the global scope. I could be utterly wrong.


I think you are right.
Section 3.4.3/4
A name prefixed by the unary scope operator :: (5.1) is looked up in
global scope, in the translation unit where it is used. The name shall
be declared in global namespace scope or shall be a name whose
declaration is visible in global scope because of a using-directive
(3.4.3.2). The use of :: allows a global name to be referred to even
if its identifier has been hidden (3.3.7).


I stand corrected. Personally it seems kinda weird, but thems the
breaks. I wonder why the decision was made that using the "::" scope
operation still goes through the "search path"... I would have figured
that by saying "::" you _meant_ global only...


Isn't the point is that there isn't a search path? Once you use 'using
namespace xxx;' within the global namespace all the names in xxx *are*
global.

john
Jul 22 '05 #21
"John Harrison" <jo************ *@hotmail.com> wrote in
news:2l******** ****@uni-berlin.de:

"Andre Kostur" <nn******@kostu r.net> wrote in message
news:Xn******** *************** ********@207.35 .177.134...
"Sharad Kala" <no************ ******@yahoo.co m> wrote in
news:2l******** ****@uni-berlin.de:
>
> "John Harrison" <jo************ *@hotmail.com> wrote in message
> news:opsas0q1jt 212331@andronic us...
>> On Thu, 08 Jul 2004 05:32:45 GMT, Russell Hanneken <me@privacy.net >
>> wrote:
>>
>> > John Harrison wrote:
>> >> On Wed, 07 Jul 2004 22:20:42 GMT, Russell Hanneken
>> >> <me@privacy.net >
> [snip]
>>
>> I think I'm really going to have to look this up in the standard,
>> which is always a scary prospect. But here's a guess, your version of >> the code injects all the std namespace names into the scope of main, >> but ::string ignores any names within the scope of main and just
>> looks directly at the global scope. I could be utterly wrong.
>>
>
> I think you are right.
> Section 3.4.3/4
> A name prefixed by the unary scope operator :: (5.1) is looked up in
> global scope, in the translation unit where it is used. The name shall > be declared in global namespace scope or shall be a name whose
> declaration is visible in global scope because of a using-directive
> (3.4.3.2). The use of :: allows a global name to be referred to even
> if its identifier has been hidden (3.3.7).


I stand corrected. Personally it seems kinda weird, but thems the
breaks. I wonder why the decision was made that using the "::" scope
operation still goes through the "search path"... I would have figured
that by saying "::" you _meant_ global only...


Isn't the point is that there isn't a search path? Once you use 'using
namespace xxx;' within the global namespace all the names in xxx *are*
global.


I would have figured that the "search path" would be used for unqualified
names. Much like specifying an executable in Windows or Unix. Just type
the name, and it searches $PATH for the executable. But if you specify a
full pathname to the file (like /program), then you mean just the
executable in the root directory and no other.
Jul 22 '05 #22

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

Similar topics

18
3055
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
11
1797
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I understand that you declare your intention to use a namespace within a page through the "Inherits" attribute. I know that using "Inherits" isn't absolutely necessary, it's just recommended so the developer doesn't have to type out the entire...
0
9724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10394
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.