By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

How to redefine a typedefined type?

P: n/a
For example if anywhere defined MyChar as
typedef char MyChar;

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

Jun 20 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a

On Jun 19, 10:25 pm, Amber <guxiaobo1...@gmail.comwrote:
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
Jun 20 '07 #2

P: n/a
On Jun 20, 10:45 am, Chris Fairles <chris.fair...@gmail.comwrote:
On Jun 19, 10:25 pm, Amber <guxiaobo1...@gmail.comwrote:
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
I include a .h file, which defines some class and use typedef, now I
want replace the typedef with a with my ower type.
Jun 20 '07 #3

P: n/a
On Jun 19, 10:23 pm, Amber <guxiaobo1...@gmail.comwrote:
On Jun 20, 10:45 am, Chris Fairles <chris.fair...@gmail.comwrote:
On Jun 19, 10:25 pm, Amber <guxiaobo1...@gmail.comwrote:
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

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.

Jun 20 '07 #4

P: n/a
On Jun 20, 11:25 am, Amber <guxiaobo1...@gmail.comwrote:
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/

Jun 20 '07 #5

P: n/a
Amber wrote:
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.

--
Ian Collins.
Jun 20 '07 #6

P: n/a
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;

Jun 20 '07 #7

P: n/a
Amber wrote:
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.

--
Ian Collins.
Jun 20 '07 #8

P: n/a
On Jun 20, 2:55 am, Amber <guxiaobo1...@gmail.comwrote:
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?

Jun 20 '07 #9

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

Jun 20 '07 #10

P: n/a
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;

Jun 21 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.