The following program attempts to construct a second string using the first string and a pointer into the middle of the first string:
#include <string>
int main() {
std::string src = "hello world";
const char* end = &src[5];
std::string dest(src.data(), end);
}
In C++14 and earlier this works. But in C++17 the call fails:
error: no matching function for call to ‘std::__cxx11::basic_string<char>::basic_string(char*, const char*&)’
std::string dest(src.data(), end);
[... full output omitted ...]
What changed to make this fail?
end
pointer altogether:const char* start = src.c_str(); std::string dest(start, start+5);
Or:char* start = src.data(); std::string dest(start, start+5);
Or, just use a different constructor, like:std::string dest(src.c_str(), 5);
– Boletus