Vector Errors during compile in Visual Studio 2008

Started by
12 comments, last by Zahlman 15 years, 8 months ago
Hi, I am using C++ and am compiling my code in Visual Studio 2008 on Windows XP. Previously my code compiled fine in Visual Studio 2003, but now in VS2008 it gives me the following two errors. Maybe I don't have visual studio 2008 setup right. Any ideas. Thanks.

1>error C2440: 'initializing' : cannot convert from 'int' to 'std::_Vector_iterator<_Ty,_Alloc>'
1>        with
1>        [
1>            _Ty=RECT,
1>            _Alloc=std::allocator<RECT>
1>        ]
1>        No constructor could take the source type, or constructor overload resolution was ambiguous


1>error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_Vector_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)
1>        with
1>        [
1>            _Ty=RECT,
1>            _Alloc=std::allocator<RECT>
1>        ]
1>        c:\program files\microsoft sdks\windows\v6.0a\include\guiddef.h(197): could be 'int operator !=(const GUID &,const GUID &)'
1>        c:\program files\microsoft visual studio 2008\vc\include\vector(214): or       'bool std::_Vector_const_iterator<_Ty,_Alloc>::operator !=(const std::_Vector_const_iterator<_Ty,_Alloc> &) const'
1>        with
1>        [
1>            _Ty=RECT,
1>            _Alloc=std::allocator<RECT>
1>        ]
1>        while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>, int)'
1>        with
1>        [
1>            _Ty=RECT,
1>            _Alloc=std::allocator<RECT>
1>        ]

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Advertisement
post some code.
Hi, ok.

The first error refers to this piece of code:

vector<RECT>::iterator itSearchRect=lstFilledRects.begin();vector<RECT>::iterator itBestRect=NULL;  //<<<<<===error 1 pointing hereint nSrcRectMaxBottom=0, nSrcRectMinLeft=recContainer.right;while(itSearchRect!=lstFilledRects.end())		{


The second error refers to this piece of code:

if(itBestRect!=NULL)  //<<<<<===error 2 pointing here{	RECT recSrcHole;	recSrcHole.top=itBestRect->top;	recSrcHole.left=itBestRect->left;	recSrcHole.right=itBestRect->right;	recSrcHole.bottom=itBestRect->bottom;

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Replace NULL with lstFilledRects.end().

The end function provides an "invalid" (i.e. NULL) iterator. "NULL" itself is not any kind of iterator, which is why the compiler is complaining.
I'm sure it worked okay with Null in the past on VS 2003.

Oh well then. Will do.

Thanks

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

if(itBestRect!=NULL)


Why does functions I used to use not work?

There was a function for vectors such as Empty()

But it doesn't come up?


I think I somehow still need to make my settings in Visual Studio 2008 as unmanaged / native.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

std::vector never had a function called Empty(). It did and does, however, have an empty() method.

When things that used to work with an old compiler suddenly stop working with a newer compiler, it's often because the newer compiler is stricter and more standard-compliant and thus no longer allows you to get away with certain dirty tricks.
Spelling issues aside, can somebody actually help me solve the problem.

If the vector class has a method called empty() then when I do it
eg
itBestRect.empty()

well, pressing the . brings up some wierd methods I have never seen before and does not bring up and empty() method as a possible option.
examples:
itBestRect._Adopt
itBestRect._Compat
itBestRect._Getmycont

What's with these? That's why I want to setup visual studio 8 with unmanaged code or otherwise known as native code. Because I don't want any of the fluff microsoft has added.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

Quote:Original post by utilae
Spelling issues aside, can somebody actually help me solve the problem.

If the vector class has a method called empty() then when I do it
eg
itBestRect.empty()

well, pressing the . brings up some wierd methods I have never seen before and does not bring up and empty() method as a possible option.
examples:
itBestRect._Adopt
itBestRect._Compat
itBestRect._Getmycont

What's with these? That's why I want to setup visual studio 8 with unmanaged code or otherwise known as native code. Because I don't want any of the fluff microsoft has added.
itBestRect is an iterator, not a vector. It doesn't have an empty() member.

You can call std::vector::empty() to see if a vector has zero elements in it, and you can check a std::vector::iterator against it's owning vector's std::vector::end() to see if it's the end of the container (I.e. an invalid iterator). It's not valid to check it against null - that may have worked if VC2003 used pointers instead of iterators (As some STL implementations do for std::vector), but that just means that VC2003 was letting you use incorrect code.

As for those members like _Adopt; they're used internally. Just ignore them and any other members prefixed with an underscore.
Hi thanks.

You are right.
In my focus on VS2008 and its settings, I forgot that I was for some reason thinking an iterator had an empty function.

HTML5, iOS and Android Game Development using Corona SDK and moai SDK

This topic is closed to new replies.

Advertisement