|
From: Daniel G. <sp...@ho...> - 2002-03-21 18:13:27
|
<html><div style='background-color:'><DIV></DIV>
<DIV>
<P>Could someone explain this to me a little bit clearer? Is it just saying you need to write the namespace declaration to write headers without the .h extention? If so what's the point in that?</P>
<P>Thanks,</P>
<P>Daniel</P>
<P> </P>
<P>C++ also supports namespaces. Namespaces simplify the writing of programs that combine libraries from various members. The namespace feature is not available in C. The statement that must be included in the program when using namespaces is<FONT color=#ff0000> using namespace std</FONT>;.</P>
<P>e.g.</P><FONT color=#ff0000>
<P>// This is a program to demonstrate the use of namespace.</P></FONT><FONT color=#0000ff>
<P>#include <iostream></P>
<P>using namespace std;</P></FONT><FONT color=#ff0000>
<P>void main()</P>
<P>{</P>
<P>cout << "Using Namespace";</P>
<P>}</P></FONT>
<P>In C++, if you use iostream instead of iostream.h, the namespace directive is used to make the definitions in iostream available to your program.</P></DIV></div><br clear=all><hr>MSN Photos is the easiest way to share and print your photos: <a href='http://g.msn.com/1HM305301/14'>Click Here</a><br></html>
|
|
From: Jason H. <jas...@bt...> - 2002-03-22 02:38:52
|
The use of .h headers is depreciated, meaning that in future C++ =
implementations it may not exist. It is only available for backward =
compatibilty at the moment.
Saying using namespace std; in the global scope is actualy bad =
programming practice. What you might do in a proper program is put =
something like using std::cout; in global scope and occasionally using =
namespace std; in a method, class or block of code that it would be of =
benefit for. You should avoid elevating as much as possible to the =
global scope. Elevating cout would be reasonable as it is used such a =
great deal.
One of the reasons for namespaces is, as mentioned, when multiple =
libraries are added to one project. The different libraries can each =
have thier own namespace so that if both librarys have an "add()" =
function they can be accessed seperatly and won't collide. If you had =
std in the global scope (as it used to be) then everything in that =
namespace that collides with the common names in any other global space =
library will cause the compiler to have a fit. In big projects it makes =
it easier to ensure that method names don't collide.
Jason.
----- Original Message -----=20
From: Daniel Glenfield=20
To: dev...@li...=20
Sent: Thursday, March 21, 2002 6:13 PM
Subject: [Dev-C++] Namespaces
Could someone explain this to me a little bit clearer? Is it just =
saying you need to write the namespace declaration to write headers =
without the .h extention? If so what's the point in that?
Thanks,
Daniel
C++ also supports namespaces. Namespaces simplify the writing of =
programs that combine libraries from various members. The namespace =
feature is not available in C. The statement that must be included in =
the program when using namespaces is using namespace std;.
e.g.
// This is a program to demonstrate the use of namespace.
#include <iostream>
using namespace std;
void main()
{
cout << "Using Namespace";
}
In C++, if you use iostream instead of iostream.h, the namespace =
directive is used to make the definitions in iostream available to your =
program.
-------------------------------------------------------------------------=
-----
MSN Photos is the easiest way to share and print your photos: Click =
Here
_______________________________________________ Dev-cpp-users mailing =
list Dev...@li... =
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Ioannis V. <no...@ya...> - 2002-03-22 05:07:36
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Daniel
Glenfield
Sent: Thursday, March 21, 2002 8:13 PM
To: dev...@li...
Subject: [Dev-C++] Namespaces
Could someone explain this to me a little bit clearer? Is it just saying
you need to write the namespace declaration to write headers without the
.h extention? If so what's the point in that?
Thanks,
Daniel
=20
Things are slightly different:
=20
=20
C++ also supports namespaces. Namespaces simplify the writing of
programs that combine libraries from various members. The namespace
feature is not available in C. The statement that must be included in
the program when using namespaces is using namespace std;.
=20
or std::facility.=20
=20
=20
e.g.
// This is a program to demonstrate the use of namespace.
#include <iostream>
using namespace std;=20
=20
Bad use of namespace in global scope.=20
void main()=20
void main() is not valid C++ anymore.
=20
{
cout << "Using Namespace";
}
In C++, if you use iostream instead of iostream.h, the namespace
directive is used to make the definitions in iostream available to your
program.
=20
iostream.h is not valid C++ anymore. The .h exttension is valid for the
C subset header files only.
=20
=20
Now lets explain what is a namespace. Namespace are name-scopes and its
purpose is to help using various libraries. As all features of C++ this
is a great feature too.
=20
Consider the code:
=20
#include <iostream>
#include <string>
=20
#include <daniel.h> // Contains Daniel's implementation of cout in the
daniel namespace.
=20
int main()
{
using namespace std;
=20
string s;
=20
cin>>s;
=20
daniel::cout<<s<<daniel::endl;
}
=20
=20
We could also write
=20
using daniel::cout;
using daniel::endl;=20
=20
inside main().
=20
=20
We must try to keep the using namespace name_space; and using
name_space::facility_name; as in local scope as possible. Declaring
these in the global namespace is an effort to defeat the namespace
system (bad for you).
=20
=20
Ioannis
=20
* Ioannis Vranos
* Programming pages: <http://www.noicys.d2g.com/>
http://www.noicys.d2g.com
* Alternative URL: <http://run.to/noicys> http://run.to/noicys
|
|
From: Ioannis V. <no...@ya...> - 2002-03-22 14:24:11
|
-----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Ioannis Vranos Sent: Friday, March 22, 2002 7:07 AM To: Dev-C++ Subject: RE: [Dev-C++] Namespaces We must try to keep the using namespace name_space; and using name_space::facility_name; as in local scope as possible. Declaring these in the global namespace is an effort to defeat the namespace system (bad for you). Ioannis * Ioannis Vranos * Programming pages: <http://www.noicys.d2g.com/> http://www.noicys.d2g.com * Alternative URL: <http://run.to/noicys> http://run.to/noicys Sorry for the large letters, before i press "send" everything was looking normal! Ioannis * Ioannis Vranos * Programming pages: <http://www.noicys.d2g.com/> http://www.noicys.d2g.com * Alternative URL: <http://run.to/noicys> http://run.to/noicys |