STL iterators and the std namespace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • onion_skin

    STL iterators and the std namespace

    How do I bring STL iterators into the current scope? eg.

    #include <vector>
    using std::vector;

    int main()
    {
    vector<int>::it erator it;

    return 0;
    }


    gives an error
  • Corey Murtagh

    #2
    Re: STL iterators and the std namespace

    onion_skin wrote:
    [color=blue]
    > How do I bring STL iterators into the current scope? eg.
    >
    > #include <vector>
    > using std::vector;
    >
    > int main()
    > {
    > vector<int>::it erator it;
    >
    > return 0;
    > }
    >
    >
    > gives an error[/color]

    What error, and on what compiler? I tried the above on a few different
    compilers with no errors. Comeau's online test also compiles it, albeit
    with a warning that 'variable "it" is declared but never referenced'.

    --
    Corey Murtagh
    The Electric Monk
    "Quidquid latine dictum sit, altum viditur!"

    Comment

    • onion_skin

      #3
      Re: STL iterators and the std namespace

      On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov"
      <v.Abazarov@att Abi.com> wrote:
      [color=blue]
      >"onion_skin " <onion_skin_RMV @travers.com> wrote...[color=green]
      >> How do I bring STL iterators into the current scope? eg.
      >>
      >> #include <vector>
      >> using std::vector;
      >>
      >> int main()
      >> {
      >> vector<int>::it erator it;
      >>
      >> return 0;
      >> }
      >>
      >>
      >> gives an error[/color]
      >
      >What error? The code is legal C++ and compiles fine here.
      >Perhaps the compiler you're using is not good enough? If
      >that's so, try adding 'using namespace std;' in the scope
      >of the 'main' function.
      >
      >Victor
      >[/color]


      MSVC6.0 gives the error:

      "error C2653: 'vector<int,cla ss std::allocator< int> >' : is not a
      class or namespace name"

      I don't want to use expose the entire library by using 'using
      namespace std' (although that, obviously, works)

      Comment

      • Corey Murtagh

        #4
        Re: STL iterators and the std namespace

        onion_skin wrote:
        [color=blue]
        > On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov"
        > <v.Abazarov@att Abi.com> wrote:[/color]
        <snip>[color=blue][color=green]
        >>
        >>What error? The code is legal C++ and compiles fine here.
        >>Perhaps the compiler you're using is not good enough? If
        >>that's so, try adding 'using namespace std;' in the scope
        >>of the 'main' function.
        >>
        >>Victor
        >>[/color]
        >
        >
        > MSVC6.0 gives the error:
        >
        > "error C2653: 'vector<int,cla ss std::allocator< int> >' : is not a
        > class or namespace name"[/color]

        That's interesting. Worked fine on VC++ 6.0 when I tried it. Are you
        sure you posted enough code to replicate the problem?

        --
        Corey Murtagh
        The Electric Monk
        "Quidquid latine dictum sit, altum viditur!"

        Comment

        • Victor Bazarov

          #5
          Re: STL iterators and the std namespace

          "Corey Murtagh" <emonk@slingsho t.co.nz.no.uce> wrote...[color=blue]
          > onion_skin wrote:
          >[color=green]
          > > On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov"
          > > <v.Abazarov@att Abi.com> wrote:[/color]
          > <snip>[color=green][color=darkred]
          > >>
          > >>What error? The code is legal C++ and compiles fine here.
          > >>Perhaps the compiler you're using is not good enough? If
          > >>that's so, try adding 'using namespace std;' in the scope
          > >>of the 'main' function.
          > >>
          > >>Victor
          > >>[/color]
          > >
          > >
          > > MSVC6.0 gives the error:
          > >
          > > "error C2653: 'vector<int,cla ss std::allocator< int> >' : is not a
          > > class or namespace name"[/color]
          >
          > That's interesting. Worked fine on VC++ 6.0 when I tried it.[/color]

          Are you sure? It didn't when I tried it on VC++ v6.0 sp5.
          [color=blue]
          > Are you
          > sure you posted enough code to replicate the problem?[/color]

          Are you sure _you_ tried the right code?
          ---------------------------------------------
          #include <vector>

          using std::vector;

          int main()
          {
          vector<int>::it erator it;
          return 0;
          }
          ---------------------------------------------

          Victor


          Comment

          • Tom

            #6
            Re: STL iterators and the std namespace

            Also compiles without error or warning, using MS Compiler 7.1 (now 97% C++
            compliant)

            Regards,
            Tom

            "onion_skin " <onion_skin_RMV @travers.com> wrote in message
            news:9gcjfvckb5 oshk8edfta4k119 b0dthlq4v@4ax.c om...[color=blue]
            > How do I bring STL iterators into the current scope? eg.
            >
            > #include <vector>
            > using std::vector;
            >
            > int main()
            > {
            > vector<int>::it erator it;
            >
            > return 0;
            > }
            >
            >
            > gives an error[/color]


            Comment

            • Corey Murtagh

              #7
              Re: STL iterators and the std namespace

              Victor Bazarov wrote:
              [color=blue]
              > "Corey Murtagh" <emonk@slingsho t.co.nz.no.uce> wrote...[/color]
              <snip>[color=blue][color=green]
              >>
              >>That's interesting. Worked fine on VC++ 6.0 when I tried it.[/color]
              >
              >
              > Are you sure? It didn't when I tried it on VC++ v6.0 sp5.
              >
              >[color=green]
              >> Are you
              >>sure you posted enough code to replicate the problem?[/color]
              >
              >
              > Are you sure _you_ tried the right code?[/color]

              eep... ok, I messed up. Sorry. I guess all those months of typing
              'std::' in front of every STL object has gone to my brain.

              On the upside, I can confirm that it *does* work on the following compilers:

              BCB4
              Dev-C++/MinGW32 v2.95.3-6
              g++ v2.95.4

              Also works on Comeau's online test :)

              One work-around for VC++ 6.0:

              ---------------
              #include <vector>
              #define vector std::vector

              int main()
              {
              vector<int>::it erator it;

              return 0;
              }
              ---------------

              Of course this can cause all sorts of problems, but it does appear to
              work in this specific case.

              --
              Corey Murtagh
              The Electric Monk
              "Quidquid latine dictum sit, altum viditur!"

              Comment

              • onion_skin

                #8
                Re: STL iterators and the std namespace

                On Wed, 25 Jun 2003 11:44:53 -0400, "Victor Bazarov"
                <v.Abazarov@att Abi.com> wrote:
                [color=blue]
                >"Corey Murtagh" <emonk@slingsho t.co.nz.no.uce> wrote...[color=green]
                >> onion_skin wrote:
                >>[color=darkred]
                >> > On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov"
                >> > <v.Abazarov@att Abi.com> wrote:[/color]
                >> <snip>[color=darkred]
                >> >>
                >> >>What error? The code is legal C++ and compiles fine here.
                >> >>Perhaps the compiler you're using is not good enough? If
                >> >>that's so, try adding 'using namespace std;' in the scope
                >> >>of the 'main' function.
                >> >>
                >> >>Victor
                >> >>
                >> >
                >> >
                >> > MSVC6.0 gives the error:
                >> >
                >> > "error C2653: 'vector<int,cla ss std::allocator< int> >' : is not a
                >> > class or namespace name"[/color]
                >>
                >> That's interesting. Worked fine on VC++ 6.0 when I tried it.[/color]
                >
                >Are you sure? It didn't when I tried it on VC++ v6.0 sp5.
                >[color=green]
                >> Are you
                >> sure you posted enough code to replicate the problem?[/color]
                >
                >Are you sure _you_ tried the right code?
                >---------------------------------------------
                >#include <vector>
                >
                >using std::vector;
                >
                >int main()
                >{
                > vector<int>::it erator it;
                > return 0;
                >}
                >---------------------------------------------
                >
                >Victor
                >[/color]


                This is the code
                -------------------------------------------
                #include <vector>
                using std::vector;


                int main()
                {
                vector<int>::it erator it;

                return 0;
                }

                -------------------------------------------

                Comment

                • John Harrison

                  #9
                  [OT] Re: STL iterators and the std namespace


                  "Tom" <tom@yahoo.co m> wrote in message
                  news:bdcg47$r7k mt$1@ID-133116.news.dfn cis.de...[color=blue]
                  > Also compiles without error or warning, using MS Compiler 7.1 (now 97% C++
                  > compliant)
                  >
                  > Regards,
                  > Tom
                  >[/color]

                  Where do you get 7.1 from? I'm on 7.0.9466 and I reckon I'm only 96%
                  complaint.

                  john


                  Comment

                  • Gavin Deane

                    #10
                    Re: STL iterators and the std namespace

                    Corey Murtagh <emonk@slingsho t.co.nz.no.uce> wrote in message news:<105655724 2.346679@radsrv 1.tranzpeer.net >...[color=blue]
                    > Victor Bazarov wrote:
                    >[color=green]
                    > > "Corey Murtagh" <emonk@slingsho t.co.nz.no.uce> wrote...[/color]
                    > <snip>[color=green][color=darkred]
                    > >>
                    > >>That's interesting. Worked fine on VC++ 6.0 when I tried it.[/color]
                    > >
                    > >
                    > > Are you sure? It didn't when I tried it on VC++ v6.0 sp5.
                    > >
                    > >[color=darkred]
                    > >> Are you
                    > >>sure you posted enough code to replicate the problem?[/color]
                    > >
                    > >
                    > > Are you sure _you_ tried the right code?[/color]
                    >
                    > eep... ok, I messed up. Sorry. I guess all those months of typing
                    > 'std::' in front of every STL object has gone to my brain.
                    >
                    > On the upside, I can confirm that it *does* work on the following compilers:
                    >
                    > BCB4
                    > Dev-C++/MinGW32 v2.95.3-6
                    > g++ v2.95.4
                    >
                    > Also works on Comeau's online test :)
                    >
                    > One work-around for VC++ 6.0:
                    >
                    > ---------------
                    > #include <vector>
                    > #define vector std::vector
                    >
                    > int main()
                    > {
                    > vector<int>::it erator it;
                    >
                    > return 0;
                    > }
                    > ---------------
                    >
                    > Of course this can cause all sorts of problems, but it does appear to
                    > work in this specific case.[/color]

                    A better (because it doesn't use a macro, buit still irritating
                    because it shouldn't be necessary at all) work-around for VC++ 6.0:

                    #include <vector>

                    int main()
                    {
                    std::vector<int >::iterator it;

                    return 0;
                    }

                    This VC++ 6.0 feature has got me into the habit of using fully
                    qualified names in preference to using declarations.

                    GJD

                    Comment

                    Working...