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