我的程序需要大量的 ANSI<=>UNICODE 对话,所以我想到了创建多类型对象,它比附加功能和大量新/删除更容易转换所有东西。伪代码:
class CWchar // char based
{
public:
public static implicit operator wchar_t*(CWchar cw)
{
// converting cw.data to wchar_t
// up to U+FFFF conversion needed
}
public static implicit operator char*(CWchar cw)
{
return cw.data;
}
CWchar& CWchar::operator=(const char* c)
{
data = *c;
return *this;
}
CWchar& CWchar::operator=(const wchar_t* c)
{
//conversion to char* ...
return *this;
}
// add some smart pointers, garbage collector, and leave delete
private:
char* data;
}
这真的值得编码还是我应该考虑另一种解决方案?也许已经完成了项目?或者也许我错了,这个想法很糟糕?谢谢