Click here to Skip to main content
15,904,655 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralUNICODE Pin
John R. Shaw7-Jul-05 17:17
John R. Shaw7-Jul-05 17:17 
GeneralRe: UNICODE Pin
Jose Lamas Rios7-Jul-05 18:09
Jose Lamas Rios7-Jul-05 18:09 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 8:47
John R. Shaw8-Jul-05 8:47 
GeneralRe: UNICODE Pin
Jose Lamas Rios8-Jul-05 10:10
Jose Lamas Rios8-Jul-05 10:10 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 10:55
John R. Shaw8-Jul-05 10:55 
GeneralRe: UNICODE Pin
toxcct7-Jul-05 20:21
toxcct7-Jul-05 20:21 
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 7:09
John R. Shaw8-Jul-05 7:09 
GeneralRe: UNICODE Pin
Bob Stanneveld7-Jul-05 22:03
Bob Stanneveld7-Jul-05 22:03 
John R. Shaw wrote:
Essentialy, I am dealing with a template class that takes the character type as an argument. Therefore, I need to know character type it is.

So basically you have a class that looks like this:
// in header
template <typename CharacterType >
class Foo
{
public:
    void DoFoo(CharacterType Char);
};

template <typename CharacterType>
void Foo<CharacterType>::DoFoo(CharacterType Char)
{
    // what is CharacterType?
    // do some type dependant stuff
}


If i'm correct in my assumption, read on. If not you can ignore the rest of this post.

John R. Shaw wrote:
What I need is compiler independent text feed back from the template at runtime,

What feedback do you want? Why do you want this? More important, what is it that you don't know at compile time that you need to know at runtime? If you want to know this sort of stuff (which you really don't), look here[^].

John R. Shaw wrote:
Example:
#ifdef UNICODE
std::wout << L"some string";
#else
std::out << "some string";
#endif

The above looks reasonable, but it assumes the character type. Since it is a template and it can take any character type, whether UNICODE is defined or not, it well not work.


Templates can solve this exactly. You don't want to resolve this at runtime, but at compile time. The reason for this is that you can fix your problems faster and your compiler shouts tons of errors at you when you are about to make a big mistake in your program! You don't want to go into debugging trouble for type dependant stuff.

Consider the following:
>// in header
template <typename CharacterType >
class CharacterDependantClass
{
public:
    void DoFoo(CharacterType Char);
};

template <typename CharacterType>
void CharacterDependantClass<CharacterType>::DoFoo(CharacterType Char)
{
    // what is CharacterType?
    // do some type dependant stuff
}

// after the implementation
// use a typedef that you use throughout your program
#ifdef UNICODE
typedef CharacterDependantClass<wchar_t> ClassType;
#else
typedef CharacterDependantClass<char> ClassType;
#endif


If you use an wchar_t string when UNICODE is not defined, you get compiler errors, which is exactly what you want.

Behind every great black man...
            ... is the police. - Conspiracy brother


Blog[^]
GeneralRe: UNICODE Pin
John R. Shaw8-Jul-05 8:39
John R. Shaw8-Jul-05 8:39 
GeneralRe: UNICODE Pin
Bob Stanneveld9-Jul-05 5:48
Bob Stanneveld9-Jul-05 5:48 
Generalrget r, g or b value for opengl Pin
cell517-Jul-05 16:27
cell517-Jul-05 16:27 
GeneralRe: rget r, g or b value for opengl Pin
Jose Lamas Rios7-Jul-05 16:44
Jose Lamas Rios7-Jul-05 16:44 
Generalneed help on generate report to excel Pin
firebolt777-Jul-05 16:05
firebolt777-Jul-05 16:05 
GeneralRe: need help on generate report to excel Pin
Jose Lamas Rios7-Jul-05 17:09
Jose Lamas Rios7-Jul-05 17:09 
GeneralRe: need help on generate report to excel Pin
firebolt777-Jul-05 20:03
firebolt777-Jul-05 20:03 
GeneralRe: need help on generate report to excel Pin
Jose Lamas Rios7-Jul-05 20:12
Jose Lamas Rios7-Jul-05 20:12 
GeneralRe: need help on generate report to excel Pin
firebolt777-Jul-05 20:25
firebolt777-Jul-05 20:25 
GeneralRe: need help on generate report to excel Pin
firebolt778-Jul-05 3:36
firebolt778-Jul-05 3:36 
GeneralRe: need help on generate report to excel Pin
urxlnc0077-Jul-05 19:23
urxlnc0077-Jul-05 19:23 
GeneralRe: need help on generate report to excel Pin
firebolt777-Jul-05 21:36
firebolt777-Jul-05 21:36 
GeneralHelp finding wmstub.lib Pin
Lan_Zer07-Jul-05 13:20
Lan_Zer07-Jul-05 13:20 
GeneralRe: Help finding wmstub.lib Pin
Christian Graus7-Jul-05 16:45
protectorChristian Graus7-Jul-05 16:45 
Generalgetting a correct structure data Pin
Ista7-Jul-05 12:40
Ista7-Jul-05 12:40 
GeneralRe: getting a correct structure data Pin
ldaoust7-Jul-05 15:12
ldaoust7-Jul-05 15:12 
GeneralMemory for my application Pin
Ivan Cachicatari7-Jul-05 11:50
Ivan Cachicatari7-Jul-05 11:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.