Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   STL iterators and the std namespace (http://www.velocityreviews.com/forums/t267707-stl-iterators-and-the-std-namespace.html)

onion_skin 06-25-2003 02:41 PM

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

Corey Murtagh 06-25-2003 03:11 PM

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!"


onion_skin 06-25-2003 03:20 PM

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)

Corey Murtagh 06-25-2003 03:29 PM

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!"


Victor Bazarov 06-25-2003 03:44 PM

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



Tom 06-25-2003 03:48 PM

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




Corey Murtagh 06-25-2003 04:07 PM

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!"


onion_skin 06-25-2003 05:37 PM

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;
}

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

John Harrison 06-25-2003 05:49 PM

[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



Gavin Deane 06-26-2003 12:49 AM

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 12:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.