2013-12-12 22 views
0

基本上我想創建一個宏說是否可以創建一個宏來在C/C++中創建一致的函數聲明?

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

我不知道我在做什麼錯,但我想要做的是聲明一組過濾函數都具有相同的聲明,所以我可以將它們作爲函數指針傳遞給更通用的功能。

+2

爲什麼你用圓括號包裝定義? –

+2

你應該在查詢之前查看預處理器輸出。 – chris

+0

是的,我應該有。謝謝你提醒我。我很少發現需要。 – penguin4hire

回答

2

從宏中取出額外的括號。

#define DECLARE_FILTER_FUNC(fname, arg1) PointCloud<PointXYZ>::Ptr fname(PointCloud<PointXYZ>::Ptr arg1) 
相關問題