2 vengel Vengel 于 2016.01.21 16:44 提问

函数类型作为模板的类型参数,could not deduce template argument for 'T' 20C

模板定义:

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

请大神帮帮忙,怎么解决啊~~~

2个回答

caozhy
caozhy   Ds   Rxr 2016.01.21 16:52

说的很清楚,没办法推定类型,因为你的函数参数没有ContextAcessor,所以不知道它的类型,需要指定下
http://stackoverflow.com/questions/19221183/could-not-deduce-template-argument-for-t

Vengel
Vengel   2016.01.21 17:28

如果要指定类型,那么需要同时指定UnaryFunction和ContextAcessor的类型, ContextAcessor的类型我知道怎么指定,但是UnaryFunction的类型怎么指定?ApplyPostponedStateForApp是类StateController的**成员函数**,如何指定它作为UnaryFunction的类型?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!