错误:没有匹配函数来调用'min(long unsigned int&,unsigned int&)'

时间:2013-01-24 18:17:52

标签: c++ gcc ubuntu boost

我使用的是ubuntu 12.04 - 64位。我用boost 1.46,1.48,1.52和。来测试它 gcc 4.4和4.6 当我尝试编译时:

while (m_burstReqBeatsRemain) {
                if (m_burstReqAddress % m_dramRowSize == 0) {
                    m_admRequestQueue.push_back(adm_request());
                    adm_request &req = m_admRequestQueue.back();
                    req.address = m_burstReqAddress;
                    req.command = tlm::TLM_READ_COMMAND;
                    //call to min function
                    req.readLen = std::min(m_burstReqBeatsRemain * sizeof(Td), m_dramRowSize);
                }
                m_burstReqBeatsRemain--;
                m_burstReqAddress += sizeof(Td);
                m_ocpTxnQueue.push_back(m_ocpReq);
}

我收到此错误:

no matching function for call to ‘min(long unsigned int&, unsigned int&)
from /usr/include/c++/4.6/bits/stl_algobase.h*

注意:使用ubuntu 12.04 32位工作正常

知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:42)

std::minT上的函数模板,它是函数的两个参数的类型。但是你似乎传递了不同类型的函数参数,依赖于函数参数的模板参数推导,这是不可能的。

所以修复是:

  • 要么不依赖模板参数推导,而是明确提及模板参数:

    std::min<unsigned long>(ulongarg, uintarg); //ok
         //^^^^^^^^^^^^^^^ 
         //don't rely on template argument deduction
         //instead pass template argument explicitly.
    
  • 或传递相同类型的函数参数:

    std::min(ulongarg, static_cast<unsigned long>(uintarg)); //ok
                      //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                      //pass both arguments of same type