Jump to content
  • Advertisement
Sign in to follow this  
derek_nofsinger

c2679: Not sure what to do.

This topic is 3810 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

I'm upgrading code from Visual Studio 6 to Visual Studio 2005 and I'm absolutely stumped on what the compiler is complaing about. C2679. I've been reviewing the code over and over. error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Position *' Not exactly sure how to overload the vector '=' operator either and hopefully I can just fix the bug in the code that gives me the error. Here it is: void Graphics::RemoveDuplicatePositions(){ Vector<Position>:: pos_it; int vec_size = positions.size(); for(int i = 0; i < vec_size && vec_size != 1) { pos_it = &positions; //ERROR HERE: C2679 'Position *' if(positions == positions[(i + 1) % vec_size]) { positions.erase(pos_it); vec_size = positions.size(); } else { i++; } }//end loop } What do I need to do to fix this problem? (I wish I could copy and paste this but, I'm typing it by hand from referring to the computer that has Visual Studio yet no internet connection)

Share this post


Link to post
Share on other sites
Advertisement
Use [ source ] tags.

You want:
pos_it = positions.begin() + i;

Pointers are a kind of iterator, but nowhere in the C++ standard does it say you can create a vector<T>::iterator from an arbitrary pointer, like your current code does. Since VS6 takes the shoddy route of just making vector::iterators actual pointers to it's internal buffer, it compiles your code. VS2005 provides nice features like debug iterators, and stiffens up what kind of code it will accept, which is arguably a good thing.

Share this post


Link to post
Share on other sites
The error is pretty obvious, its saying that you can't make an iterator from a pointer. Which is true. Fortunately, with random access iterators one can make an iterator from a begin() position and an index very intuitively:

vec.begin() + index;


For a non-random access, it can still be done but ain't so pretty:

std::vector<SomeType>::iterator it = vec.begin();
std::advance(it,index);


However, there may be a better way. It appears you are trying to remove duplicates from a sorted container. Then, perhaps consider std::unique? Remember the golden rule: if it seems like a common task, someone's already written it for you:

void Graphics::RemoveDuplicatePositions()
{
positions.erase(std::unique(positions.begin(),positions.end()),positions.end());
}

Share this post


Link to post
Share on other sites
What is Vector? It doesn't look like std::vector to me and if it isn't then we don't know what pos_it is. But you're missing an identifier there so who knows? Actually, if you're totally against 'duplicate positions' there's a chance there are better containers for the job like std::set (if you don't care about order). Also, you're code will miss duplicates if it is not ordered. My best guess is that if you used std::vector in VC++ 6.0 that MS's implementation was that the iterator was just a normal pointer instead of a wrapper. Additionally, the size changes when you erase an element yet you do not take that into account in your code.

Right now it's hard to give advice without knowing more about positions. Do you want no duplicates ever? Does order matter? If the answers are yes and no then check out std::set.

edit: I forgot about std::unique

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!