宏处理两对圆括号
C++ Macro - process two pairs of parentheses
我需要预处理这段代码:
line (0,0) (5,5)
,其中(0,0)表示起始x和y坐标,第二个(5,5)表示结束x和y坐标。
我可以使用
获取起始坐标#define line(x1,y1) myArray->shapes.push_back(new Line(x1,y1));
如何处理第二个括号?
不如这样写:
struct LineCreator {
LineCreator(type_of_shapes &shapes, int x1, int y1)
: shapes_(shapes), x1_(x1), y1_(y1)
{}
void operator() (int x2, int y2) {
shapes_.push_back(new Line(x1_, y1_, x2, y2));
}
private:
type_of_shapes &shapes_;
int x1_, y1_;
};
#define line(x, y) LineCreator(myArray->shapes, (x), (y))
改为:
line (0,0,5,5)
现在可以构造以下宏:
#define line(x1,y1,x2,y2) myArray->shapes.push_back(new Line(x1,y1));
myArray->shapes.push_back(new Line(x2,y2));
相关文章:
- 警告处理为错误这里有什么问题
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 使用流处理接收到的数据
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 基于多个条件处理地图中的所有元素
- 如何用数字处理log(0)
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- C++decltype和圆括号-为什么
- 错误处理.将系统错误代码映射到泛型
- 从文本文件中读取时钟时间和事件时间并进行处理
- 在运行时处理类型擦除的数据-如何不重新发明轮子
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 用于矢量处理的多个线程
- 对字符串进行排序时,在c++中处理sort()
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- 处理除以零会导致<csignal>意外行为
- 宏处理两对圆括号