| Author |
accessing static array of structs
|
|
|
| Have STL question:
Just tried compiling the some code with visual studio 2005. it can’t get
past this code which VS 2003 had no problem with:
I have a static array of structs which I want to operate on
Struct SOMESTRUCT
{
Int i1;
Int i2;
};
typedef std::vector<SOMESTRUCT>::iterator someStructIter ;
Const int NUM = 4 ;
SOMESTRUCT anArrayOfSomeStructs [NUM] =
{
…… the static initializers
};
someFunc()
{
…
for (someStructIter it = anArrayOfSomeStructs ; &*it != &
anArrayOfSomeStructs [NUM] ; ++it)
.. do something nasty to it
}
vs2005 doesn’t like the iter assignment:
someStructIter it = anArrayOfSomeStructs
thanks
Al
| |
| red floyd 2006-02-15, 7:04 pm |
| Al wrote:
> Have STL question:
>
> Just tried compiling the some code with visual studio 2005. it can’t get
> past this code which VS 2003 had no problem with:
>
> I have a static array of structs which I want to operate on
>
> Struct SOMESTRUCT
> {
> Int i1;
> Int i2;
> };
>
>
> typedef std::vector<SOMESTRUCT>::iterator someStructIter ;
> Const int NUM = 4 ;
> SOMESTRUCT anArrayOfSomeStructs [NUM] =
> {
> …… the static initializers
> };
>
> someFunc()
> {
> …
> for (someStructIter it = anArrayOfSomeStructs ; &*it != &
> anArrayOfSomeStructs [NUM] ; ++it)
> .. do something nasty to it
> }
>
> vs2005 doesn’t like the iter assignment:
> someStructIter it = anArrayOfSomeStructs
because an iterator into a vector is not a pointer. If you want to use
a vector use a vector. If you want to use an array, use a pointer.
e.g.
std::vector<SOMESTRUCT> v(anArrayOfSomeStructs,anArrayOfSomeStru
ct+NUM);
for (someStructIter it = v.begin(); it != v.end; ++v)
{
}
or
for (SOMESTRUCT* p = anArrayOfSomeStruct;
p != anArrayOfSomeStruct + NUM;
++p)
{
}
but you can't mix them the way you did.
| |
|
| thanks .... that fixed it.
the way i had it did work in vs2003 though. :o)
--
Al
"red floyd" wrote:
> Al wrote:
>
>
> because an iterator into a vector is not a pointer. If you want to use
> a vector use a vector. If you want to use an array, use a pointer.
>
> e.g.
>
> std::vector<SOMESTRUCT> v(anArrayOfSomeStructs,anArrayOfSomeStru
ct+NUM);
> for (someStructIter it = v.begin(); it != v.end; ++v)
> {
> }
>
> or
>
> for (SOMESTRUCT* p = anArrayOfSomeStruct;
> p != anArrayOfSomeStruct + NUM;
> ++p)
> {
> }
>
> but you can't mix them the way you did.
>
>
| |
| Tom Widmer [VC++ MVP] 2006-02-16, 8:01 am |
| Al wrote:
> thanks .... that fixed it.
>
> the way i had it did work in vs2003 though. :o)
Still, programming solely by trial and error, rather than reading
documentation to determine how to do something, is generally not a good
idea.
Tom
| |
|
| point taken :o)
--
Al
"Tom Widmer [VC++ MVP]" wrote:
> Al wrote:
>
> Still, programming solely by trial and error, rather than reading
> documentation to determine how to do something, is generally not a good
> idea.
>
> Tom
>
| |
|
| BTW ... is there a known problem with vs2005 locking up XP?
i'm using vs2005 on several large projects and XP is totally locking up
about once a day. i never saw this with vs2003.
thanks again
--
Al
"Tom Widmer [VC++ MVP]" wrote:
> Al wrote:
>
> Still, programming solely by trial and error, rather than reading
> documentation to determine how to do something, is generally not a good
> idea.
>
> Tom
>
|
|
|
|