![]() |
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>::iterator it; return 0; } gives an error |
Re: STL iterators and the std namespace
onion_skin wrote:
> How do I bring STL iterators into the current scope? eg. > > #include <vector> > using std::vector; > > int main() > { > vector<int>::iterator it; > > return 0; > } > > > gives an error 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!" |
Re: STL iterators and the std namespace
On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov"
<v.Abazarov@attAbi.com> wrote: >"onion_skin" <onion_skin_RMV@travers.com> wrote... >> How do I bring STL iterators into the current scope? eg. >> >> #include <vector> >> using std::vector; >> >> int main() >> { >> vector<int>::iterator it; >> >> return 0; >> } >> >> >> gives an error > >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,class 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) |
Re: STL iterators and the std namespace
onion_skin wrote:
> On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov" > <v.Abazarov@attAbi.com> wrote: <snip> >> >>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,class std::allocator<int> >' : is not a > class or namespace name" 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!" |
Re: STL iterators and the std namespace
"Corey Murtagh" <emonk@slingshot.co.nz.no.uce> wrote...
> onion_skin wrote: > > > On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov" > > <v.Abazarov@attAbi.com> wrote: > <snip> > >> > >>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,class std::allocator<int> >' : is not a > > class or namespace name" > > That's interesting. Worked fine on VC++ 6.0 when I tried it. Are you sure? It didn't when I tried it on VC++ v6.0 sp5. > Are you > sure you posted enough code to replicate the problem? Are you sure _you_ tried the right code? --------------------------------------------- #include <vector> using std::vector; int main() { vector<int>::iterator it; return 0; } --------------------------------------------- Victor |
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:9gcjfvckb5oshk8edfta4k119b0dthlq4v@4ax.com... > How do I bring STL iterators into the current scope? eg. > > #include <vector> > using std::vector; > > int main() > { > vector<int>::iterator it; > > return 0; > } > > > gives an error |
Re: STL iterators and the std namespace
Victor Bazarov wrote:
> "Corey Murtagh" <emonk@slingshot.co.nz.no.uce> wrote... <snip> >> >>That's interesting. Worked fine on VC++ 6.0 when I tried it. > > > Are you sure? It didn't when I tried it on VC++ v6.0 sp5. > > >> Are you >>sure you posted enough code to replicate the problem? > > > Are you sure _you_ tried the right code? 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>::iterator 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!" |
Re: STL iterators and the std namespace
On Wed, 25 Jun 2003 11:44:53 -0400, "Victor Bazarov"
<v.Abazarov@attAbi.com> wrote: >"Corey Murtagh" <emonk@slingshot.co.nz.no.uce> wrote... >> onion_skin wrote: >> >> > On Wed, 25 Jun 2003 11:06:12 -0400, "Victor Bazarov" >> > <v.Abazarov@attAbi.com> wrote: >> <snip> >> >> >> >>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,class std::allocator<int> >' : is not a >> > class or namespace name" >> >> That's interesting. Worked fine on VC++ 6.0 when I tried it. > >Are you sure? It didn't when I tried it on VC++ v6.0 sp5. > >> Are you >> sure you posted enough code to replicate the problem? > >Are you sure _you_ tried the right code? >--------------------------------------------- >#include <vector> > >using std::vector; > >int main() >{ > vector<int>::iterator it; > return 0; >} >--------------------------------------------- > >Victor > This is the code ------------------------------------------- #include <vector> using std::vector; int main() { vector<int>::iterator it; return 0; } ------------------------------------------- |
[OT] Re: STL iterators and the std namespace
"Tom" <tom@yahoo.com> wrote in message news:bdcg47$r7kmt$1@ID-133116.news.dfncis.de... > Also compiles without error or warning, using MS Compiler 7.1 (now 97% C++ > compliant) > > Regards, > Tom > Where do you get 7.1 from? I'm on 7.0.9466 and I reckon I'm only 96% complaint. john |
Re: STL iterators and the std namespace
Corey Murtagh <emonk@slingshot.co.nz.no.uce> wrote in message news:<1056557242.346679@radsrv1.tranzpeer.net>...
> Victor Bazarov wrote: > > > "Corey Murtagh" <emonk@slingshot.co.nz.no.uce> wrote... > <snip> > >> > >>That's interesting. Worked fine on VC++ 6.0 when I tried it. > > > > > > Are you sure? It didn't when I tried it on VC++ v6.0 sp5. > > > > > >> Are you > >>sure you posted enough code to replicate the problem? > > > > > > Are you sure _you_ tried the right code? > > 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>::iterator it; > > return 0; > } > --------------- > > Of course this can cause all sorts of problems, but it does appear to > work in this specific case. 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 |
| All times are GMT. The time now is 04:13 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.