C++ : Exception occurred in script: basic_string::_S_construct NULL not valid

You cannot return NULL (or 0) from a function that is declared to return string because there is no appropriate implicit conversion. You might want to return an empty string though

return string();

or

return "";

If you want to be able to distinguish between a NULL value and an empty string, then you will have to use either pointers (smart ones, preferrably), or, alternatively, you could use std::optional (or boost::optional before C++17)

Leave a Comment