我有以下代码:
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow)
{
int serialport = getCommandLineOption<int>(lpCmdLine, "-com", atoi);
...
template<typename T>
T getCommandLineOption(const std::string& commandLine, const std::string& option, std::function<T(const char*)> f)
{
auto result = getCommandLineOption(commandLine, option);
return result.empty() ? T() : f(result.c_str());
}
const std::string getCommandLineOption(std::string commandLine, std::string option)
{
...
然后我删除了
functional
并将模板函数更改为:
template<typename T, typename F>
T getCommandLineOption(const std::string& commandLine, const std::string& option, F f)
{
auto result = getCommandLineOption(commandLine, option);
return result.empty() ? T() : f(result.c_str());
}
现在在
WinMain
在那里我调用函数以获取串行端口参数,我不能省略int类型规范,但我
可以
省略函数指针类型规范。为什么?
PS:
getCommandLineOption
函数位于静态库中,静态库由包含
程序进入点
.