[英]error: no matching function for call to ‘min(long unsigned int&, unsigned int&)’
I'm using ubuntu 12.04 - 64 bits.我正在使用 ubuntu 12.04 - 64 位。 I tested it with boost 1.46, 1.48, 1.52 and gcc 4.4 and 4.6 When I try to compile:
我用 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);
}
I get this error:我收到此错误:
no matching function for call to ‘min(long unsigned int&, unsigned int&)
from /usr/include/c++/4.6/bits/stl_algobase.h*
Note: with ubuntu 12.04 32 bits works fine注意:ubuntu 12.04 32 位工作正常
Any idea how I can fix this?知道我该如何解决这个问题吗?
std::min
is a function template on T
which is the type of both parameters of the function. std::min
是T
上的函数模板,它是函数的两个参数的类型。 But you seem to pass function arguments of different type, and rely on template argument deduction from function arguments, which is not possible. 但是你似乎传递了不同类型的函数参数, 并依赖于函数参数的模板参数推导,这是不可能的。
So the fix is : 所以修复是:
Either don't rely on template argument deduction, instead explicitly mention the template argument: 要么不依赖模板参数推导,而是明确提到模板参数:
std::min<unsigned long>(ulongarg, uintarg); //ok //^^^^^^^^^^^^^^^ //don't rely on template argument deduction //instead pass template argument explicitly.
Or pass function arguments of same type: 或传递相同类型的函数参数:
std::min(ulongarg, static_cast<unsigned long>(uintarg)); //ok //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //pass both arguments of same type
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
Define your template for min and max it will not give error.为 min 和 max 定义模板不会出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.