Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2008 -> VS2010 leads to cryptic STL errors

The following C++ library was successfully compiled in VS2008

http://sourceforge.net/projects/xmlrpcc4win/files/xmlrpcc4win/XmlRpcC4Win1.0.8.zip/download

When I open it in VS2010, it goes through the conversion wizard process without any errors.

Now, when I attempt to compile it in VS2010, I get some weird STL errors like these:

1>TimXmlRpc.cpp(1018): error C2039: 'back_insert_iterator' : is not a member of 'std'
1>TimXmlRpc.cpp(1018): error C2065: 'back_insert_iterator' : undeclared identifier
1>TimXmlRpc.cpp(1018): error C2275: 'XmlRpcValue::BinaryData' : illegal use of this type as an expression
1>TimXmlRpc.cpp(1018): error C2065: 'ins' : undeclared identifier
1>TimXmlRpc.cpp(1018): error C2039: 'back_inserter' : is not a member of 'std'
1>TimXmlRpc.cpp(1018): error C3861: 'back_inserter': identifier not found
1>TimXmlRpc.cpp(1019): error C2065: 'ins' : undeclared identifier
1>TimXmlRpc.cpp(1031): error C2039: 'back_insert_iterator' : is not a member of 'std'
1>TimXmlRpc.cpp(1031): error C2065: 'back_insert_iterator' : undeclared identifier
1>TimXmlRpc.cpp(1031): error C2275: 'std::vector<_Ty>' : illegal use of this type as an expression
1>          with
1>          [
1>              _Ty=char
1>          ]
1>TimXmlRpc.cpp(1031): error C2065: 'ins' : undeclared identifier
1>TimXmlRpc.cpp(1031): error C2039: 'back_inserter' : is not a member of 'std'
1>TimXmlRpc.cpp(1031): error C3861: 'back_inserter': identifier not found
1>TimXmlRpc.cpp(1032): error C2065: 'ins' : undeclared identifier

I'm not sure what to make of some of these. For instance, back_insert_iterator is in fact a member of std, but VS doesn't seem to think it is.

How do I fix errors like these? They just don't seem to make much sense so I'm not sure where to begin. Perhaps its something in my project settings?

For example, here is line 1018, which gives the std error:

std::back_insert_iterator<BinaryData> ins = std::back_inserter(*(u.asBinary));

If anyone could give me some direction I'd appreciate it. I'm new enough to C++ that I'm having a tough time figuring out this one.

like image 376
Jake Wilson Avatar asked Jun 02 '10 15:06

Jake Wilson


2 Answers

You probably forgot #include <iterator> in some of your files. That's where things like back_insert_iterator are declared.

In the past, you could get away with forgetting that header file, since many of the other standard headers also included it. VS2010 reorganized the headers for its library implementation to be more standards compliant. As a result, it's much less forgiving of missing headers, and <iterator> is a commonly overlooked one.

like image 128
Adrian McCarthy Avatar answered Nov 03 '22 02:11

Adrian McCarthy


From MSDN:

The header is no longer included automatically by many other header files. Instead, include that header explicitly if you require support for the standalone iterators defined in the header.

http://msdn.microsoft.com/en-us/library/bb531344.aspx

like image 28
Sean Hubbell Avatar answered Nov 03 '22 01:11

Sean Hubbell