Topic: Help with correctly using namespaces


Author: Darin Adler <darin@bentspoon.com>
Date: 1999/12/14
Raw View
Boyd R Pukalo <qz3fwd@hqs.mid.gmeds.com> wrote:

> Now to use vector without always writing std::vector I have using
> std::vector in Grid.h.

Normally, I avoid putting using statements in headers, since they force the
"using" on anyone else including the header.

> My compiler will not compile unless I write
> std::vector<int>::iterator. Even if I include <iterator> and using
> std::iterator in the header file the compiler will not compile without
> the std::vector<int>::iterator in the implementation. Is this
> correct? I thought that the statement using std::vector was all that was
> necesssary? Is this a Microsoft Visual C++ 6 issue? Whats going on?

Yes, this is a problem with your compiler.

This simple test program should work, and it works fine with my compiler:

    #include <vector>
    using std::vector;
    int main()
    {
        vector<int> v(1, 0);
        vector<int>::iterator i = v.begin();
        return *i;
    }

    -- Darin
---
[ 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: Boyd R Pukalo <qz3fwd@hqs.mid.gmeds.com>
Date: 1999/12/12
Raw View
Suppose I have a class called Grid with an associated member function
Grid::Build(void). This class uses std::vector and includes the <vector>
header.
Now to use vector without always writing std::vector I have using
std::vector in Grid.h. Implemented in Grid.cxx, the member function
Grid::Build(void) uses temporary vectors and a vector iterator, such as
vector<int>::iterator i. My compiler will not compile unless I write
std::vector<int>::iterator. Even if I include <iterator> and using
std::iterator in the header file the compiler will not compile without
the std::vector<int>::iterator in the implementation. Is this
correct? I thought that the statement using std::vector was all that was
necesssary? Is this a Microsoft Visual C++ 6 issue? Whats going on?
Thanks in advance.
      Boyd Pukalo
      qz3fwd@home.com
---
[ 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              ]