auto decide - char or wchar_t

C

Christopher

My book tells me that the compiler will automagically decide whether to
instantiate a basic_iostream with char or wchar_t and I want to do the same
with my class derived from the basic_iostream. I looked at the
implementation of iostream that came with my environment and I found:

#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
template class _CRTIMP2_PURE basic_iostream<char, char_traits<char> >;
template class _CRTIMP2_PURE basic_iostream<wchar_t, char_traits<wchar_t> >;

my instinct would tell me to put the same defines for my derived class, but
I don't think that would be very portable, as I believe _DLL_CPPLIB,
_M_CEE_PURE, and _CRTIMP2_PURE to be MS specific or worse even compiler
specific. Is there some portable way to accomplish the same thing?

Even if I use #ifdef #endif blocks I wouldn't know what to put in them for
these defines for other OSes/Compilers.
Any advice?
 
J

Jim Langston

Christopher said:
My book tells me that the compiler will automagically decide whether
to instantiate a basic_iostream with char or wchar_t and I want to do
the same with my class derived from the basic_iostream. I looked at
the implementation of iostream that came with my environment and I
found:
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
template class _CRTIMP2_PURE basic_iostream<char, char_traits<char> >;
template class _CRTIMP2_PURE basic_iostream<wchar_t,
char_traits<wchar_t> >;
my instinct would tell me to put the same defines for my derived
class, but I don't think that would be very portable, as I believe
_DLL_CPPLIB, _M_CEE_PURE, and _CRTIMP2_PURE to be MS specific or
worse even compiler specific. Is there some portable way to
accomplish the same thing?
Even if I use #ifdef #endif blocks I wouldn't know what to put in
them for these defines for other OSes/Compilers.
Any advice?

I dont think it's the defines that are doing the deciding, but the fact that
there are two templates declared, one for char, one for wchar_t. If you
look at the #else there is probably 2 definitions after it just without
_CRTIMP2_PURE most likely. As it is, you still need to specify which
template to use. Take a look at your declaration of ifstream, for example,
and see how it decides which to instantize.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top