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.
Can I overload the std::string constructor?
Nope, it would require changing std::string declaration.
I want to create a constructor which takes std::wstring and return a std::string. is it possible and how?
You can have a conversion function instead, like:
std::string to_string(std::wstring const& src);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With