简体   繁体   English

错误:没有匹配的 function 调用 'min(long unsigned int&, unsigned int&)'

[英]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::minT上的函数模板,它是函数的两个参数的类型。 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 定义模板不会出错。

不匹配调用 '(const Y) (int&amp;, std::mersenne_twister_engine <long unsigned int,< div><div id="text_translate"><p> 有我的.hpp:</p><pre> #include &lt;random&gt; #include &lt;ctime&gt; #include &lt;cmath&gt; #ifndef RECUIT_HPP #define RECUIT_HPP template &lt; class E, class Func, class TempSeq, class RandomY, class RNG&gt; E recuit_simule(const Func &amp; phi, E x0, const TempSeq &amp; T, const RandomY &amp; Y, RNG &amp; G, long unsigned N) { std::uniform_real_distribution&lt;double&gt; U(0,1); E y; double u; for(int i=0; i&lt;N; i++) { y=Y(x0, G); u=U(G); if(u &lt;= fmin(1, exp((phi(x0) - phi(y))/T(N)))) { x0=y; } } return x0; } #endif</pre><p> 和我的.cpp:</p><pre> #include "recuit.hpp" #include &lt;iostream&gt; class Y { private: std::normal_distribution&lt;double&gt; N; public: Y(): N(0,1) {} double operator()(const double &amp; x, std::mt19937 &amp; G) { return x + N(G); } }; int main() { auto phi=[](const double &amp; x) { return x*x*x*x*x*x - 48*x*x; }; auto T=[] (long unsigned n) { return 10 * pow(0.9, n); }; YA; std::mt19937 G; double x = recuit_simule(phi, 0, T, A, G, 1000); std::cout &lt;&lt; x &lt;&lt; std::endl; return 0; }</pre><p> 当我编译 my.cpp 时,my.hpp 中有以下错误:</p><blockquote><p> recuit.hpp:17:6: 错误: 不匹配调用 '(const Y) (int&amp;, std::mersenne_twister_engine&amp;)'</p></blockquote><p> 对于该行:</p><pre> y=Y(x0, G);</pre><p> 我不明白为什么</p></div></long> - no match for call to ‘(const Y) (int&, std::mersenne_twister_engine<long unsigned int,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有匹配函数调用带有union_set的&#39;get(long unsigned int *&,long unsigned int&)&#39; - error: no matching function for call to ‘get(long unsigned int*&, long unsigned int&)’ with union_set 没有从long unsigned int转换为long unsigned int& - No conversion from long unsigned int to long unsigned int& 在另一个错误中调用一个函数:“没有匹配的函数来调用`merge(int *&,int&,int&,int&)” - Calling one function inside of another error: “no matching function for call to `merge(int*&, int&, int&, int&)” 没有匹配的函数来调用&#39;QGridLayout :: addWidget(QPushButton,int&,int&) - no matching function for call to 'QGridLayout::addWidget(QPushButton, int&, int&) 没有匹配呼叫&#39;(std :: pair <unsigned int, unsigned int> )(unsigned int&,unsigned int)&#39; - No match for call to '(std::pair<unsigned int, unsigned int>) (unsigned int&, unsigned int)' 没有匹配的 function 用于调用“距离 (int&amp;,int&amp;)” - no matching function for call to 'distance (int&,int&)' 不匹配调用 '(const Y) (int&amp;, std::mersenne_twister_engine <long unsigned int,< div><div id="text_translate"><p> 有我的.hpp:</p><pre> #include &lt;random&gt; #include &lt;ctime&gt; #include &lt;cmath&gt; #ifndef RECUIT_HPP #define RECUIT_HPP template &lt; class E, class Func, class TempSeq, class RandomY, class RNG&gt; E recuit_simule(const Func &amp; phi, E x0, const TempSeq &amp; T, const RandomY &amp; Y, RNG &amp; G, long unsigned N) { std::uniform_real_distribution&lt;double&gt; U(0,1); E y; double u; for(int i=0; i&lt;N; i++) { y=Y(x0, G); u=U(G); if(u &lt;= fmin(1, exp((phi(x0) - phi(y))/T(N)))) { x0=y; } } return x0; } #endif</pre><p> 和我的.cpp:</p><pre> #include "recuit.hpp" #include &lt;iostream&gt; class Y { private: std::normal_distribution&lt;double&gt; N; public: Y(): N(0,1) {} double operator()(const double &amp; x, std::mt19937 &amp; G) { return x + N(G); } }; int main() { auto phi=[](const double &amp; x) { return x*x*x*x*x*x - 48*x*x; }; auto T=[] (long unsigned n) { return 10 * pow(0.9, n); }; YA; std::mt19937 G; double x = recuit_simule(phi, 0, T, A, G, 1000); std::cout &lt;&lt; x &lt;&lt; std::endl; return 0; }</pre><p> 当我编译 my.cpp 时,my.hpp 中有以下错误:</p><blockquote><p> recuit.hpp:17:6: 错误: 不匹配调用 '(const Y) (int&amp;, std::mersenne_twister_engine&amp;)'</p></blockquote><p> 对于该行:</p><pre> y=Y(x0, G);</pre><p> 我不明白为什么</p></div></long> - no match for call to ‘(const Y) (int&, std::mersenne_twister_engine<long unsigned int, 错误:没有匹配的函数可以调用“ make_pair(int&,Quest *)” - error: no matching function for call to 'make_pair(int&, Quest*)' 无法从“ unsigned int”转换为“ unsigned int&” - could not convert from 'unsigned int' to 'unsigned int&' 重载 'min(int&amp;, int&amp;)' 的调用不明确 - call of overloaded 'min(int&, int&)' is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM