Can I overload the std::string constructor?
I want to create a constructor which takes std::wstring and return a std::string. is it possible and how?
Thanks.
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.
Nope, it would require changing
std::stringdeclaration.You can have a conversion function instead, like:
However, you need to decide what to do with symbols that can’t be represented using 8-bit encoding of
std::string: whether to convert them to multi-byte symbols or throw an exception. See wcsrtombs function.