How to redefine a typedefined type?

A

Amber

For example if anywhere defined MyChar as
typedef char MyChar;

Now I want to redefine MyChar as wchar_t, how can I do this?
 
C

Chris Fairles

For example if anywhere defined MyChar as
typedef char MyChar;

Now I want to redefine MyChar as wchar_t, how can I do this?


Redefine in what context? If its in a different scope, you can simply:

typedef wchar_t MyChar;

but I'm guessing you can't do that in your case (whatever it may be).
More info?

Chris
 
A

Amber

Redefine in what context? If its in a different scope, you can simply:

typedef wchar_t MyChar;

but I'm guessing you can't do that in your case (whatever it may be).
More info?

Chris

I include a .h file, which defines some class and use typedef, now I
want replace the typedef with a with my ower type.
 
Z

Zachary Turner

I include a .h file, which defines some class and use typedef, now I
want replace the typedef with a with my ower type.

Unfortunately it's not possible.
 
S

Sarath

For example if anywhere defined MyChar as
typedef char MyChar;

Now I want to redefine MyChar as wchar_t, how can I do this?

I exactly can't predict on what context you need to behave like this.
typedef is a compile time operator.
In my assumption, you are trying to do a typdefinition according to
some other definitions. Like UNICODE..

In that context you can do as follwos

#ifdef UNICODE // or the symbol you need
typedef char MyChar;
#else
typedef wchar_t MyChar;
#endif

You only need to define or undefine symbol as per your requirement.

Regards,
Sarath
http://sarathc.wordpress.com/
 
I

Ian Collins

Amber said:
For example if anywhere defined MyChar as
typedef char MyChar;

Now I want to redefine MyChar as wchar_t, how can I do this?
You can't redefine a typedef in the same scope.
 
A

Amber

I am using loki, in my case somebody defines XXXList as typelist with
some types,
and I am going to appand another type to the list, and then typedef
the new list as XXXList;
 
I

Ian Collins

Amber said:
I am using loki, in my case somebody defines XXXList as typelist with
some types,
and I am going to appand another type to the list, and then typedef
the new list as XXXList;
Were you replying to me? Please retain enough context for your post to
make sense.

One solution would be to put your stuff in its own namespace.
 
Z

Zachary Turner

I am using loki, in my case somebody defines XXXList as typelist with
some types,
and I am going to appand another type to the list, and then typedef
the new list as XXXList;

You need to call it something else. By the time it reaches your new
typedef, a lot of code and files have already been compiled using the
old typedef. What would be your expected behavior? Would it change
the old code to use the new typelist, or would the old code get the
old value and any future code get the new value?
 
R

rep_movsd

A crude way is to #define so the given typename actually means
something else (textually) in your code.
Use at your own risk....
 
A

Amber

OK, the actual thing I want is to make sure some strings constants are
unique at complie time, for example:

template<const char * text>
class Unit{
public:
const char * GetName(){return text;}
};
//--------------------------------
1.h
const char[] s1 = "Handler1";

typedef TYPELIST_1(Unit<s1>)) HandlerList;

//------------------------------------------
2.h
#include "1.h"

const char[] s2 = "Handler2";
typedef Appand<Unit<s2>, HandlerList>::Result HandlerList;
 

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

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top