gpt4 book ai didi

c++ - 是否可以创建一个宏来在 C/C++ 中创建一致的函数声明?

转载 作者:行者123 更新时间:2023-11-28 03:02:05 25 4
gpt4 key购买 nike

基本上我想创建一个宏说

DECLARE_FUNC(name, arg1)

这将定义函数的名称和参数的名称。

我曾尝试执行以下操作但失败了

#define DECLARE_FILTER_FUNC(fname, arg1) (PointCloud<PointXYZ>::Ptr fname(PointCloud<PointXYZ>::Ptr arg1))

然后我这样定义函数

DECLARE_FILTER_FUNC(filterStatOutlierRemoval, inputCloud)
{
return inputCloud;
}

我期待它扩展到

PointCloud<PointXYZ>::Ptr orcFilterStatOutlierRemoval(PointCloud<PointXYZ>::Ptr inputCloud)
{
return inputCloud;
}

当我编译时我得到

error: expected constructor, destructor, or type conversion before ‘(’ token

我不确定我做错了什么,但我想做的是声明一组具有相同声明的过滤器函数,这样我就可以将它们作为函数指针传递,以获得更通用的功能。

最佳答案

从宏中去掉多余的括号。

#define DECLARE_FILTER_FUNC(fname, arg1) PointCloud<PointXYZ>::Ptr fname(PointCloud<PointXYZ>::Ptr arg1)

关于c++ - 是否可以创建一个宏来在 C/C++ 中创建一致的函数声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20534718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com