0

I am migrating the visual studio 2008 vc++ projects to visual studio 2013. I am facing c3892 when migrating one of my projects.Here I am providing sample piece of code which reproduces the the error Iam facing in migration.

int _tmain(int argc, _TCHAR* argv[]){
    int myints[] = {21,64,17,78,49};
    std::set<int> myset (myints,myints+5);
    std::set<int>::reverse_iterator rit;
    std::cout << "myset contains:";
    for (rit=myset.rbegin(); rit != myset.rend(); ++rit)
        if(*rit==64)
            *rit=90;
    return 0;
}

If we execute the above piece of code in vs2013 ,Iam throwing an error

Error error C3892: 'std::_Revranit<_RanIt,_Base>::operator *' : you cannot assign to a variable that is const   

But if we execute the same piece of code visual studio 2008, Iam not getting any type of errors the build is successful.

I must change the value in my project. Please provide me the solution how to get rid of this error.

Thanks in advance. phani

BitNinja
  • 1,477
  • 1
  • 19
  • 25
  • you r not only migrating to vs13 but under the hood migrating to C++ 11. i am not fully sure about the error. But check the coding standard and changed syntax for c++ 11 once. – Newton Sheikh Feb 14 '14 at 07:12

1 Answers1

0

Simply put, you're not allowed to directly modify elements of a set after they've been inserted (http://www.cplusplus.com/reference/set/set/). If you changed set to vector in your example, it would compile just fine.

If you want to modify an element from a set, you must erase it from the set and then insert the modified value.

Actually, this stackoverflow question is identical to yours and has some cool workarounds suggested.

Community
  • 1
  • 1
AndyG
  • 39,700
  • 8
  • 109
  • 143