On Mon, Nov 16, 2015 at 6:42 PM, Stephan Beal <sgbeal at googlemail.com> wrote:

> On Mon, Nov 16, 2015 at 6:11 PM, Igor Korot <ikorot01 at gmail.com> wrote:
>
>> The variables referenced are defined as "std::string" and the code is in
>> C++.
>>
>
> the std::string(char const *) constructor does  not, last time i checked,
> accept a NULL value. You will need to pass it "" in that case.
>
> [stephan at host:~/tmp]$ cat foo.cpp
> #include <string>
>
> int main(){
>     std::string s(0);
>     return 0;
> }
>

Minor clarification: what you're doing is using the copy constructor, which
also doesn't like NULL:

[stephan at host:~/tmp]$ cat foo.cpp
int main(){
    //std::string s(0);
    std::string s = 0;
    return 0;
}

[stephan at host:~/tmp]$ gcc -o foo foo.cpp -lstdc++

[stephan at host:~/tmp]$ ./foo
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
Aborted


-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf

Reply via email to