[英]Call function parameters in C++11 using variadic templates
關注@ Xeo的優秀代碼 :
我想知道如何模板函數的返回類型,以便不通過以下方式解釋返回:
std::string* out_opt
它可以為給定的函數返回適當的類型。
另外,關於@ Xeo的示例代碼,我想知道綁定具有多個參數的成員函數的最佳方法是什么...
func_dict["someFunc"] = stream_function<int(int,int)>( std::bind( &MyClass::functionName, instanceOfMyClass, std::_1, std::_2 ) );
這是一個好方法嗎? 有沒有辦法消除需要明確陳述_1,_2等?
如果這是C ++ 11,為什么不呢
func_dict["someFunc"] = stream_function<int(int,int)>(
[&](int x, int y)
{
MyClass::functionName(instanceOfMyClass, x, y);
});
否則,我認為你總是需要以某種方式明確陳述參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.