Newbie problem with the String class

Thomas Regner tomte at subdimension.com
Fri Feb 11 11:13:32 GMT 2000


On Don, 10 Feb 2000, you wrote:
> On Thu, 10 Feb 2000, you wrote:
> > Eric Rouse wrote:
> > 
> > > I was just wondering, are you using namespace with those?  You should
> > > be able to have something like...
> > > 
> > > using namespace std;
> > > 
> > > then:
> > > 
> > >    std::string myString("some text..");
> > > 
> > > Regards,
> > > Eric
> > 
> > Just another dumb question: What does this "using" command do and what
> > ist "namespace std" ?
> 
> Namespaces separate declarations to prevent name-conflicts (e.g. you have
> a "const int A=3" in a.h and a "double A=3.3" in b.h, and you #include <a.h>
> in b.h, which does not work). The "std" namespace is used by the C++ STL
> include files e.g. <string> <iostream> (notice the file is WITHOUT .h). "using"
> tells the compiler to make the namespace visible to the actual file without the
> prefix. So, if "using namespace std" is given, you can write "string s" instead
> of "std::string s".

Not only to prevent name-clashes, but to Organize your code and put in one scope
what logically/functionally belongs to one unit of your Project.
You may, as a simple comparison, think of the packages-concept of java, extend that
in a reasonable way, and, voila, reach namespaces as a convinient solution.

That you now may name two things, that do the same, but in a different context, with the same name,
a tokenizer is always a tokenizer, and its namespace scope tells you whch tokenizer you´re using, without a name-clash
is IMHO just a "sideefect".

With the exception of std, I think of the using keyword as an extension for lazy-people, cause using the full-scope
in your programs in other cases makes them easier to read and therefore easier to understand.

(just my 2 cent ;-))

> Or just take a recent C++ introduction where namespaces will be explained much
> better :-)

If you are familiar with other oo-languages, read stroustrups `the c++-programming language`,
nobody makes it clearer then the master himself ;)
> -- 
> Martin Piskernig
> <martin.piskernig at stuwo.at>    ICQ: 24015591
> The KDevelop Team           www.kdevelop.org
-- 
/--------------
| Thomas Regner			
| Kaiserstr. 5			
| 26122 Oldenburg		
| Tel.: +49 441 7775005		
| E.:   tomte at subdimension.com	
|______________________________/




More information about the KDevelop mailing list