By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,514 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,514 IT Pros & Developers. It's quick & easy.

namespaces

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
> > 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

P: n/a
<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 discussion thread is closed

Replies have been disabled for this discussion.