C++ 在宏中使用 private 和 public,在 class 内
C++ using private and public in macro, inside class
我正在尝试制作一个宏来填充我在游戏黑客中使用的 类。让我告诉你我正在尝试做什么:
#define pad(loc, size) private: \
char _pad#loc[#size]; \
public:
那么我想像这样使用它:
class C_VTable {
public:
float member; // <- public
pad(0x4, 0x30); // <- private im not sure how to make the pad name be like pad0x4
float anothermember; // <- public again
};
我该怎么做,因为我收到一条错误消息,说它需要 ;
有点乱,希望大家理解。
非常感谢任何帮助:)
使用 ##
粘贴运算符将两个标记组合在一起。另外,不要使用 #
对大小进行字符串化 - 您不需要方括号内的字符串。
#define pad(loc, size) private: \
char __pad##loc[size]; \
public:
我正在尝试制作一个宏来填充我在游戏黑客中使用的 类。让我告诉你我正在尝试做什么:
#define pad(loc, size) private: \
char _pad#loc[#size]; \
public:
那么我想像这样使用它:
class C_VTable {
public:
float member; // <- public
pad(0x4, 0x30); // <- private im not sure how to make the pad name be like pad0x4
float anothermember; // <- public again
};
我该怎么做,因为我收到一条错误消息,说它需要 ; 有点乱,希望大家理解。
非常感谢任何帮助:)
使用 ##
粘贴运算符将两个标记组合在一起。另外,不要使用 #
对大小进行字符串化 - 您不需要方括号内的字符串。
#define pad(loc, size) private: \
char __pad##loc[size]; \
public: