"Make the class template work with wide or narrow characters"

purbeast0

No Lifer
Sep 13, 2001
53,639
6,522
126
I have to do this little project where I have to make a template class. One of the requirements is the line in the topic ...

"Make the class template work with wide or narrow characters (selectable at compile time)."

Now I'm figuring that they want the class template to work with wide and narrow characters and that they will fill it in when they run the application, but I just do not even know the concept of wide or narrow characters. I've never heard this term before, and a google search did not really help me.

Could someone point me in the right direction as to what this means? I found this link here ...

http://safari.oreilly.com/0596...X/cplsian-CHP-8-SECT-3

but I still am not exactly following which direction to go.

(this is for a C++ project btw)
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Probably referring to 8-bit ascii (narrow) and larger character types (encoded using UNICODE etc, wide). being a template project and the phrase "selectable at compile time" they probably want you to make the character type a template argument so you can change it at compile time.
 

purbeast0

No Lifer
Sep 13, 2001
53,639
6,522
126
Originally posted by: alpha88
Are you using visual c++?

If so, I think you'll want to use TCHAR instead of char in all places.

http://msdn2.microsoft.com/en-...y/c426s321(VS.80).aspx

Basically, you write your code and declare variables as type TCHAR. Then at compile time, TCHAR is either converted to char (if in ANSI mode) or to wchar_t (if in UNICODE)

Well I'm doing it in visual studio, but it has to work (or should work) at all command line compilers as well.

But thanks for the information guys.

After reading more about it I'm pretty sure you guys are right in that I have to make sure my class works with both char and wchar_t types, which is going to make me have to change some code around because I was just doing everything using char's heh, and some of the stuff doesn't quite work with wchar_t :p.

Just when I thought I was almost finished, I'm not :D
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Now I'm figuring that they want the class template to work with wide and narrow characters and that they will fill it in when they run the application

They mean at compile time, not runtime. In other words, code the class using the compiler supplied types that are transparent to character width, and the associated functions for manipulating them, rather than the format-specific C runtime versions. That way, you can set compiler defines to tell the compiler what character width you want to build the application for. Do a little search on char, wchar, and tchar and it should all become clear :).