Jump to content
  • Advertisement
Sign in to follow this  
utilae

Vector Errors during compile in Visual Studio 2008

This topic is 3572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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>        ]

Share this post


Link to post
Share on other sites
Advertisement
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 here
int 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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!