Topic: Duplicate names: is this allowed?
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1999/06/30 Raw View
On 30 Jun 99 17:47:32 GMT, Stan Brown <brahms@mindspring.com> wrote:
>The motivation is that I'm preparing a Web page of reserved identifiers
>in C++, bringing together information from various clauses of the
>Standard into a single alphabetical list. Assuming that my understanding
>is correct, I don't need to list anything that's in namespace ::std,
>right?
It depends how the implementation implemenets .h header files.
If we write
// myfile.cc
#include <vector>
template <class T> class vector { ... };
int main() { vector<int>(); }
then the compiler chooses ::vector.
If we include vector.h
// myfile.cc
#include <vector.h> // only difference from above
template <class T> class vector { ... };
int main() { vector<int>(); }
Then if vector.h is implemeted as
// vector.h
#include "vector"
using namespace std;
then there is no problem. Still, the compiler chooses ::vector.
But if vector.h is implemeted as
// vector.h
#include "vector"
using std::vector;
Then the definition of class ::vector<class> in file myfile.cc is
an error as it attemps to overload a class definition.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/06/30 Raw View
Siemel Naran wrote:
>
> On 30 Jun 99 17:47:32 GMT, Stan Brown <brahms@mindspring.com> wrote:
>
> >The motivation is that I'm preparing a Web page of reserved identifiers
> >in C++, bringing together information from various clauses of the
> >Standard into a single alphabetical list. Assuming that my understanding
> >is correct, I don't need to list anything that's in namespace ::std,
> >right?
>
> It depends how the implementation implemenets .h header files.
>
> If we write
> // myfile.cc
> #include <vector>
> template <class T> class vector { ... };
> int main() { vector<int>(); }
> then the compiler chooses ::vector.
>
> If we include vector.h
> // myfile.cc
> #include <vector.h> // only difference from above
> template <class T> class vector { ... };
> int main() { vector<int>(); }
> Then if vector.h is implemeted as
> // vector.h
> #include "vector"
> using namespace std;
> then there is no problem. Still, the compiler chooses ::vector.
>
> But if vector.h is implemeted as
> // vector.h
> #include "vector"
> using std::vector;
> Then the definition of class ::vector<class> in file myfile.cc is
> an error as it attemps to overload a class definition.
However, as soon as you do
#include <vector.h>
you leave the standard area. So this problem doesn't differ from
the problem you get if you do on an unix system:
#include <unistd.h>
int pipe=0;
int main()
{
return pipe;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/07/01 Raw View
Siemel Naran wrote:
>
> On 30 Jun 99 17:47:32 GMT, Stan Brown <brahms@mindspring.com> wrote:
>
> >The motivation is that I'm preparing a Web page of reserved identifiers
> >in C++, bringing together information from various clauses of the
> >Standard into a single alphabetical list. Assuming that my understanding
> >is correct, I don't need to list anything that's in namespace ::std,
> >right?
>
> It depends how the implementation implemenets .h header files.
Stan Brown specified:
> Assumptions: 1. No "using namespace std;". 2. <cxxxx> headers, not
> <xxxx.h>
So the issue of how the implementation implements .h header files
doesn't come up.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: brahms@mindspring.com (Stan Brown)
Date: 1999/06/30 Raw View
[mods: I posted this two days ago, but it has not appeared. apologies if
the earlier copy did reach you and the queue is just backed up]
My understanding is that the names (other than macro names) in the
standard headers are all in namespace ::std, and therefore I'm free to
create my own identical names in the global namespace or in my own named
namespaces and use them as I please. Is that correct?
Assumptions: 1. No "using namespace std;". 2. <cxxxx> headers, not
<xxxx.h>
Example:
#include <cstddef>
static int prtdiff_t; // perverse, but should be legal?
I'm really trying to check that my understanding is correct here. This
isn't some sort of trick question, though if there are exceptions I'd
like to know about them.
The motivation is that I'm preparing a Web page of reserved identifiers
in C++, bringing together information from various clauses of the
Standard into a single alphabetical list. Assuming that my understanding
is correct, I don't need to list anything that's in namespace ::std,
right?
--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.mindspring.com/~brahms/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]