2
我想传递重载函数指针,如下面的示例代码中所示。C++重载函数指针模糊
class Sample
{
uint32_t method(char* input1, double input2);
uint32_t method(double input1);
}
template<class T, class... Args)
void processInput(T &&t, Args&&... a)
{
std::packaged_task<uint32_t(Args...)> task(std::bind(t, a...));
// other processing
}
// Caller invokes the below API
Sample* obj = new Sample();
processInput(static_cast<uint32_t(*)(double)>(&Sample::method), &*obj, 2.0f);
但是这段代码不能编译。它一直抱怨它无法确定哪个重载函数实例是有意的。我提到的几个例子:
http://en.cppreference.com/w/cpp/language/static_cast
可在指出别人的帮助是怎么回事错在这里?
Shoudln't'的static_cast <双(*)(双)>'是'的static_cast',因为它是一个成员函数? –
NathanOliver
@pree修复你的拼写错误(缺少';',''''而不是'>')。该函数也不返回'double'。 – LogicStuff
就是这样!我真的不明白static_cast在函数重载中的实现,并且做错了!谢谢@NathanOliver&LogicStuff。 – pree