I have a function foo(const std::string& str); that it does crash if you call it using foo(NULL).
What can I do to prevent it from crashing?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
std::string has a constructor that takes a const char* parameter. That’s constructor is going to crash when you pass NULL to it, and that constructor is called implicitly when you write foo(NULL).
The only solution I can think of is to overload foo