问题描述
- 函数类型作为模板的类型参数,could not deduce template argument for 'T'
-
模板定义:template <typename UnaryFunction, typename ContextAcessor> void ForEachApplication(UnaryFunction func) { using namespace utils; typename ContextAcessor::ApplicationListAccessor accessor; typedef typename ContextAcessor::ApplictionSetConstIt Iter; for (Iter it = accessor.begin(); it != accessor.end(); ++it) { if (it->valid()) { ApplicationConstSharedPtr const_app = *it; func(ContextAcessor::instance()->application(const_app->app_id())); } } }
模板调用:
void StateController::TempStateStopped(HmiState::StateID ID) { LOG4CXX_AUTO_TRACE(logger_); { sync_primitives::AutoLock autolock(active_states_lock_); active_states_.remove(ID); } ForEachApplication(std::bind1st(std::mem_fun(&StateController::ApplyPostponedStateForApp), this)); }
编译错误:
error C2783: 'void application_manager::StateController::ForEachApplication(UnaryFunction)' : could not deduce template argument for 'ContextAcessor'
编译环境:win7_x64+vs2008
请大神帮帮忙,怎么解决啊~~~
解决方案
说的很清楚,没办法推定类型,因为你的函数参数没有ContextAcessor,所以不知道它的类型,需要指定下
http://stackoverflow.com/questions/19221183/could-not-deduce-template-argument-for-t
解决方案二:
如果要指定类型,那么需要同时指定UnaryFunction和ContextAcessor的类型, ContextAcessor的类型我知道怎么指定,但是UnaryFunction的类型怎么指定?ApplyPostponedStateForApp是类StateController的**成员函数**,如何指定它作为UnaryFunction的类型?
时间: 2024-11-08 20:19:02