Re: Whats the difference? string and std::string

From: Gavin Deane (deane_gavin_at_hotmail.com)
Date: 11/23/03


Date: 23 Nov 2003 07:28:39 -0800

Robert W Hand <rwhand@NOSPAMoperamail.com> wrote in message news:<8v31sv44vq9aqnp6bfa1hqq2i8sish1gjg@4ax.com>...
> On 20 Nov 2003 06:58:28 -0800, deane_gavin@hotmail.com (Gavin Deane)
> wrote:
>
> >Robert W Hand <rwhand@NOSPAMoperamail.com> wrote in message news:<m49prvgmap6nhjm0cm6o1q0sp8e2lhd2pv@4ax.com>...
> >
> ><snip>
> >
> >> >Also what is the standard using namespace or std::?
> >>
> >> Both, although many would prefer avoiding the directive. In
> >> particular, you should not use the directive in a header.
> >
> >Just to clarify for the OP ...
> >
> >In a header you should avoid using directives (eg using namespace
> >std;) _and_ avoid using declarations (eg using std::string;). Always
> >fully qualify the name, ie everywhere you have a string, declare it as
> >std::string my_string;
> >
> >Otherwise you force anyone who includes your header to accept the
> >using declaration or directive, whether they want it or not.
>
> Sorry, that statement is not quite correct. For example, common style
> allows using declarations in class definitions that are found in
> header files.
>
> I believe that we are both writing about dumping names from a
> namespace into the global namespace with little or no warning to
> client programmers. Such a practice leads to the possibility of name
> clashing. In very large programs, name clashing is a serious problem.
> I agree that using declarations and using directives can be misused as
> you point out.

All agreed. Thanks for the further clarification Bob.

GJD



Relevant Pages

  • Re: managing header files
    ... The chances that every source file needs every other source file's header is approximately nil. ... When a system gets to hundreds of source files, this can reduce the compilation time significantly because the compiler reads fewer files. ... while in the .h files the external declarations showed no arguments. ...
    (comp.lang.c.moderated)
  • Re: Thoughts on file organisation
    ... on stdlib.h for its declarations, ... recommend not to use header guards. ... functions, one for I/O, and none for system calls. ... the files in /sys/include correspond to libraries. ...
    (comp.lang.c)
  • Re: Design orientated C question
    ... C++) definitions and function declarations. ... So isn't this structure definition allowed in my header? ... "Every .cpp file that uses structure/class definitions or function ... have everthing it needs to access any member of a structure within the array ...
    (microsoft.public.vc.language)
  • Re: How to distribute a C program into many C files ?
    ... >this is the first question a C programmer asks after learning C basics, ... them in one C file and have extern declarations in a header. ... CLC FAQ ...
    (comp.lang.c)
  • Re: [PATCH] proc_fs.h redux
    ... struct file_operations; ... The only realistic solution is to use forward declarations. ... problem is to correctly pull the declarations from the and ... header in the correct order. ...
    (Linux-Kernel)