Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make one class have two names?

Tags:

c++

I'm using a library that has only one difference between platforms/versions. One version calls the class btCollisionObject and other versions call it btCollisionObjectWrapper. If I could make this class have two names that still reference that class then all my problems would be solved. I tried: #define btCollisionObject btCollisionObjectWrapper; but it is not working. What is the correct way to give a class two names after the class has been defined?

like image 252
SteveDeFacto Avatar asked Dec 22 '12 23:12

SteveDeFacto


People also ask

Can a class have multiple names?

To assign multiple classes to a single HTML element, you need to specify each class name inside the class attribute separated with a blank space. A class name that has more than one word is commonly joined with a dash ( - ) this is also known as the kebab-case.

How do you give multiple class names?

To specify multiple classes, separate the class names with a space, e.g. <span class="left important">.

Can you have two class names in HTML?

HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them. If the same property is declared in both rules, the conflict is resolved first through specificity, then according to the order of the CSS declarations.

How do I give multiple class names in react?

If you want to add multiple class names, you can add it to the className attribute by separating with spaces.


2 Answers

Maybe

typedef btCollisionObjectWrapper btCollisionObject;

Better to do it using language tools instead of the preprocessor.

like image 145
K-ballo Avatar answered Oct 26 '22 10:10

K-ballo


If I understand your problem correctly you will have to find a way of determining which platform you are compiling for, because I don't know which platforms you are using I can't give any advice on this however it is probably possible to do so via macros.

The solution to your problem will probably look a bit like this.

In C++98 using a type declaration

#ifdef __PLATFORM_SPECIFIC_DEFINE
    typedef btCollisionObjectWrapper btCollisionObject;
#endif

In C++11 using an alias declaration, this has the added advantage that they may be used with templates however in your case you could get away with a simple typedef.

#ifdef __PLATFORM_SPECIFIC_DEFINE
    using btCollisionObject = btCollisionObjectWrapper;
#endif

This will allow you to use btCollisionObject as the class name for the platform that uses btCollisionObjectWrapper

You will of course have to replace the __PLATFORM_SPECIFIC_DEFINE with a macro that is defined by the platform that uses btCollisionObjectWrapper.

like image 33
ctor Avatar answered Oct 26 '22 11:10

ctor