VENGEL 2016-01-21 08:44 采纳率: 0%
浏览 3270
已结题

函数类型作为模板的类型参数,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

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

  • 写回答

2条回答 默认 最新

  • threenewbee 2016-01-21 08:52
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条