How to make one class two names?

I use a library that has only one difference between platforms / versions. One version calls the btCollisionObject class, while other versions call btCollisionObjectWrapper. If I could make this class two names that still refer to this class, then all my problems will be solved. I tried: #define btCollisionObject btCollisionObjectWrapper; but it does not work. What is the correct way to give class names two after class definition?

+6
source share
2 answers

Can

 typedef btCollisionObjectWrapper btCollisionObject; 

It is better to do this using language tools instead of a preprocessor.

+11
source

If I understand your problem correctly, you will need to find a way to determine which platform you are compiling on, because I do not know which platforms you are using. I cannot give any advice on this, however, perhaps it is possible for this with macros.

The solution to your problem will probably look something like this.

In C ++ 98 using type declaration

 #ifdef __PLATFORM_SPECIFIC_DEFINE typedef btCollisionObjectWrapper btCollisionObject; #endif 

In C ++ 11, with the alias declaration, this added the advantage that they can be used with templates, however in your case you can get rid of a simple typedef.

 #ifdef __PLATFORM_SPECIFIC_DEFINE using btCollisionObject = btCollisionObjectWrapper; #endif 

This will allow btCollisionObject be used as the class name for a platform using btCollisionObjectWrapper

Of course, you should replace __PLATFORM_SPECIFIC_DEFINE macro that is defined by the platform using btCollisionObjectWrapper .

+7
source

All Articles