473,387 Members | 1,464 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,387 software developers and data experts.

namespaces

I have been having a problem with namespaces. This may be a Win-MFC issue,
but am I correct that the following should have file level scope?

using namespace MyNamespace;

Is there a way for me to declare this to have program scope?
What I would like, is to have a namespace with commonly used functions and
classes, available with program scope.

For you with experience on many different types of compilers, is this
implemented differently on different compilers? In other words, could that
be the issue?

John
Th*************@hotmail.com
Oct 23 '05 #1
4 2202
"The Code Master" <Th*************@hotmail.com> wrote in message
news:Z%*****************@newssvr25.news.prodigy.ne t
I have been having a problem with namespaces. This may be a Win-MFC
issue, but am I correct that the following should have file level
scope?

using namespace MyNamespace;
Assuming it is declared at global scope in the file, yes.
Is there a way for me to declare this to have program scope?
Only by putting it in a header that is #included in every file.
What I would like, is to have a namespace with commonly used
functions and classes, available with program scope.

For you with experience on many different types of compilers, is this
implemented differently on different compilers? In other words,
could that be the issue?


It is a language issue, not a compiler issue (except that compilers may, of
course, offer non-standard extensions that permit all sorts of things not
specified in the standard).
--
John Carson

Oct 23 '05 #2
The Code Master wrote:
I have been having a problem with namespaces. This may be a Win-MFC issue,
but am I correct that the following should have file level scope?

using namespace MyNamespace;

Is there a way for me to declare this to have program scope?
What I would like, is to have a namespace with commonly used functions and
classes, available with program scope.
Why put these functions into a namespace if the goal is to make them
available in the global namespace? The goal here would appear to be at
odds with the steps being taken.
For you with experience on many different types of compilers, is this
implemented differently on different compilers? In other words, could that
be the issue?


The issue would appear to be declaring the functions and classes in the
wrong namespace. Generally, the implementor places the interface to the
implementation in a namespace. Clients of the implementation can decide
to bring those names into their global namespace when and where they
wish. If the implementor decides that the interface should be in the
global namespace of every client, then he or she should simply declare
the interface in the global namespace to start with, rather than
declare it somewhere else and then have to figure out how to move it.

Greg

Oct 23 '05 #3
> > Is there a way for me to declare this to have program scope?

Only by putting it in a header that is #included in every file.

Except this is not good practice. Using declarations and using
directives should not be used in header files. Why?

The short answer is because the effect of these statements can
depend on the the order of includes!!

Item #59 of Sutter and Alexandrescu's C++ Coding Standards gives
all the gory details and some very good examples to explain how
this can occur.

Oct 23 '05 #4
<An**********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com
Is there a way for me to declare this to have program scope?


Only by putting it in a header that is #included in every file.

Except this is not good practice. Using declarations and using
directives should not be used in header files. Why?

The short answer is because the effect of these statements can
depend on the the order of includes!!

Item #59 of Sutter and Alexandrescu's C++ Coding Standards gives
all the gory details and some very good examples to explain how
this can occur.


Quite so, though if it was a header file that was to be included in every
file, you would normally standardize on always including it first.

--
John Carson

Oct 23 '05 #5

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

Similar topics

18
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...
24
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
2
by: Mike Morse | last post by:
What see sample that show xs:element where the xs namespace = http://www.w3.org/2001/XMLSchema However, I see another example with xsi: where xsi = http://www.w3.org/2001/XMLSchema-instance ...
3
by: Jim Heavey | last post by:
Trying to get the hang of Namespaces. I have primarly developed in VB and am transitioning to C# and the .Net Environment. I have worked a bit with Java as well in school about a year or so ago....
17
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not...
11
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.