I was reading Why would a copy constructor have more than one parameter?.
The accepted answer says that:
The old std::basic_string
does have one too:
basic_string(const basic_string& s,
size_type pos = 0, size_type n = npos)
But http://www.cplusplus.com/reference/string/basic_string/basic_string/ says that:
basic_string (const basic_string& str, size_type pos, size_type len = npos,
const allocator_type& alloc = allocator_type());
The above isn't a copy constructor but substring constructor that copies the portion of str
that begins at the character position pos
and spans len
characters.
C++ standard section says that:
A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments
So, Is the accepted answer from that link is incorrect? Is this really basic_string class constructor for sub-string? I've checked prototype for this in C++98, C++11 & C++14 specification on the link & all shows the same.
pos
parameter. Also, thebasic_string
spec does contain abasic_string(const basic_string&)
constructor. – Ting