如何使用宏#define更改类名? [英] how to use macro #define to change class name?
本文介绍了如何使用宏#define更改类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类
class A{}
但我想使用宏用以下语句替换类名A:
But I want to use macro to replace the class name A with the following statement:
#define SOMETHING A
class A {}
的定义与MACRO在同一个.cpp中。
The definition of class A {}
is in the same .cpp with the MACRO.
是否正确?
我想这样做,因为我删除了源代码中的所有MACRO。但是MACRO被广泛使用。
I want to do this, because I am removing all of the MACRO in the source code. But the MACRO was used widely. Does any software could help me to do the replacement of MACRO ?
推荐答案
颠倒令牌; #define A SOMETHING
应该工作。
Reverse the tokens; #define A SOMETHING
should work.
请注意,这是一个可怕的想法,因为它可能会破坏其他代码和混淆
Note that it is a terrible idea as it may break other code and confuse the hell out of people.
使用别名:
class A { … };
using SOMETHING = A;
这篇关于如何使用宏#define更改类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文