T
Tomás
Let's start off with:
class Nation {
public:
virtual const char* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const char* GetName() const
{
return "Norway";
}
};
Let's say we want to give the name of the nation in the nation's official
language... and so we want to use the Unicode character set to achieve this.
How does one go about using Unicode in portable code? Something like the
following?:
typedef wchar_t UnicodeChar;
class Nation {
public:
virtual const UnicodeChar* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const UnicodeChar* GetName() const
{
return L"Norway"; //Note the preceding L
}
};
Would you use "wchar_t", or would you use "unsigned short"? (Unicode is 16-
bit).
Furthermore, how do you go about making your code in such a way that it can
use either normal characters or wide characters. Microsoft do it something
like the following: (You define the UNICODE macro if you're using Unicode)
#ifdef UNICODE
typedef wchar_t Character;
#define StringLiteral(x) Lx
#else
typedef char Character;
#define StringLiteral(x) x
#endif
class Nation {
public:
virtual const Character* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const Character* GetName() const
{
return StringLiteral("Norway");
}
};
What do you think of this? At the moment I'm writing code which I want to
support the normal character set and also Unicode... but I want to keep it
portable!
Any suggestions on how to go about this? Is the Microsoft way decent enough?
-Tomás
class Nation {
public:
virtual const char* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const char* GetName() const
{
return "Norway";
}
};
Let's say we want to give the name of the nation in the nation's official
language... and so we want to use the Unicode character set to achieve this.
How does one go about using Unicode in portable code? Something like the
following?:
typedef wchar_t UnicodeChar;
class Nation {
public:
virtual const UnicodeChar* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const UnicodeChar* GetName() const
{
return L"Norway"; //Note the preceding L
}
};
Would you use "wchar_t", or would you use "unsigned short"? (Unicode is 16-
bit).
Furthermore, how do you go about making your code in such a way that it can
use either normal characters or wide characters. Microsoft do it something
like the following: (You define the UNICODE macro if you're using Unicode)
#ifdef UNICODE
typedef wchar_t Character;
#define StringLiteral(x) Lx
#else
typedef char Character;
#define StringLiteral(x) x
#endif
class Nation {
public:
virtual const Character* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const Character* GetName() const
{
return StringLiteral("Norway");
}
};
What do you think of this? At the moment I'm writing code which I want to
support the normal character set and also Unicode... but I want to keep it
portable!
Any suggestions on how to go about this? Is the Microsoft way decent enough?
-Tomás