Answer the question
In order to leave comments, you need to log in
What is the best way to implement localization?
We have this code...
namespace loc {
const wchar_t* get(const char* key);
}
struct TaggedCWstr
{
const PluralRule* rule;
const wchar_t* text;
operator const wchar_t* () const { return text; }
operator std::wstring () const { return text; }
};
namespace loc {
TaggedCWstr get(const char* key);
}
std::wstring xxx() {
return loc::get(key); // could not convert from TaggedCWstr to wstring
}
std::wstring s;
s = loc::get("key"); // ambiguous overload for op=
Answer the question
In order to leave comments, you need to log in
s = loc::get("key"); // ambiguous overload for op=
std::wstring
(copy constructor and conversion constructor from const wchar_t*
) are implicit. TaggedCWstr
are also implicit. std::wstring_view
. std::wstring
and thereby allow uncontrolled access to dynamic memory without an explicit understanding of this process. It is better to std::wstring
do for getting operator *
, and even better - not to break the semantics of operators at all and make a method with a telling name.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question