std::string insert method has ambiguous overloads?
Posted
by sdg
on Stack Overflow
See other posts from Stack Overflow
or by sdg
Published on 2010-05-12T14:15:51Z
Indexed on
2010/05/12
14:24 UTC
Read the original article
Hit count: 288
Environment: VS2005 C++ using STLPort 5.1.4.
Compiling the following code snippet:
std::string copied = "asdf";
char ch = 's';
copied.insert(0,1,ch);
I receive an error:
Error 1 error C2668: 'stlpx_std::basic_string<_CharT,_Traits,_Alloc>::insert' : ambiguous call to overloaded function
It appears that the problem is the insert method call on the string object.
The two defined overloads are
void insert ( iterator p, size_t n, char c );
string& insert ( size_t pos1, size_t n, char c );
But given that STLPort uses a simple char* as its iterator, the literal zero in the insert method in my code is ambiguous.
So while I can easily overcome the problem by hinting such as
copied.insert(size_t(0),1,ch);
My question is: is this overloading and possible ambiguity intentional in the specification? Or more likely an unintended side-effect of the specific STLPort implementation?
(Note that the Microsoft-supplied STL does not have this problem as it has a class for the iterator, instead of a naked pointer)
© Stack Overflow or respective owner