Note that there are some explanatory texts on larger screens.

plurals
  1. POerror C2783 Could not deduce template arguments
    text
    copied!<p>I am stuck with this error . <strong>I have found a workaround too but it kind of kills the whole purpose of exercise.</strong></p> <p>I am trying to create a function which will take two iterators pointing to same container . I will find the sum of elements between them. I created general function for the sequential containers like vector which works fine. I overloaded the same function for associative containers. This is the one giving error.</p> <pre><code>map&lt;string,double&gt; myMap; myMap["B"]=1.0; myMap["C"]=2.0; myMap["S"]=3.0; myMap["G"]=4.0; myMap["P"]=5.0; map&lt;string,double&gt;::const_iterator iter1=myMap.begin(); map&lt;string,double&gt;::const_iterator iter2=myMap.end(); cout&lt;&lt;"\nSum of map using the iterator specified range is: "&lt;&lt;Sum(iter1,iter2)&lt;&lt;"\n"; //Above line giving error. Intellisense is saying: Sum, Error: no instance of overloaded function "Sum" matches the argument list. //function to calculate the sum is listed below (It appears in a header file with &lt;map&gt; header included): template &lt;typename T1,typename T2&gt; double Sum(const typename std::map&lt;T1,T2&gt;::const_iterator&amp; input_begin,const typename std::map&lt;T1,T2&gt;::const_iterator&amp; input_end) { double finalSum=0; typename std::map&lt;T1,T2&gt;::const_iterator iter=input_begin; for(iter; iter!=input_end; ++iter) { finalSum=finalSum+ (iter)-&gt;second; } return finalSum; } </code></pre> <p>Compilation error is: 1>c:\documents and settings\ABC\my documents\visual studio 2010\projects\demo.cpp(41): error C2783: 'double Sum(const std::map::const_iterator &amp;,const std::map::const_iterator &amp;)' : could not deduce template argument for 'T1'</p> <p><strong>Workaround:</strong></p> <p>If call Sum(iter1,iter2) is replaced with Sum &lt; string,double > (iter1,iter2), it compiles fine. </p> <p>Was I trying to do something impossible as per C++ standards in the first place?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload