在C 中遇到宏的麻烦
Having trouble with macros in C++
我正在尝试编写C 宏来使用模板和类似的颜色名称来定义一堆子类:
#define DECLARE_SET_ELEMENT(color) class ##color##SetElement : public SetElement { public: ##color##SetElement(std::string name); int getValue() override; };
,我可以像以下方式一样使用它:
DECLARE_SET_ELEMENT(Blue) // -> class BlueSetElement ...
DECLARE_SET_ELEMENT(Red) // -> class RedSetElement ...
...
但是宏定义似乎无法正常工作。我应该按照我的意图工作?
使用
#define DECLARE_SET_ELEMENT(color) class color##SetElement : public SetElement { public: color##SetElement(std::string name); int getValue() override; };
而是。在这种情况下,领先的##
不合适。您不想将class
关键字与color
结合。
相关文章:
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 查找奇数平方和时遇到麻烦
- CSUF EPP - 你有什么想法(在添加到链接列表末尾时遇到麻烦)
- 我的期末考试遇到了麻烦.代码不断循环回到我的订购菜单,不会显示我的总价
- 作为一个C++新手,我遇到了麻烦
- MySQL 从注入过渡到参数化时遇到麻烦
- C++击球平均值程序使用输入/输出文件打印名称,平均值,最高/最低平均值时遇到麻烦
- 以分类方式插入节点时遇到麻烦
- 在此任务上遇到麻烦,我们需要使用指针和数组来找到文本文件中某些数字的平均值,中值和模式
- C++释放矢量元素占用的内存时遇到的麻烦
- 我在这个程序上遇到了麻烦.只有1个编译错误
- 我的基本蛮力计划遇到了麻烦.具体的类功能
- 我在DFS搜索(树)代码中遇到麻烦.我如何打破递归
- 我在处理字符时遇到麻烦
- 在我的代码覆盖本身时遇到麻烦,我不确定为什么
- 遇到无效旅行的麻烦::d是游戏
- C++处理文件,在制作程序时遇到麻烦
- 在客户端/服务器计算器C 方面遇到麻烦
- 在C 中遇到宏的麻烦
- 在C 的模板编程中遇到了麻烦