T __cdecl plus(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::all
ocator<char> > &)' : could not deduce template argument for 'T'什么意思?
6 个解决方案
#include<iostream>
#include<string>
using namespace std;
using std::string;
template<class T> T plus(const T &a,const T &b);
int main(){
string s=plus(static_cast<string>("he"), static_cast<string>("llo"));
cout<< s;
return 0;
}
template<class T> T plus (const T& a,const T& b){
return a+b;
}
中间为何要那样引用???string s=plus(static_cast<string>("he"), static_cast<string>("llo"));
#include <cmath>
double (*a[])(double)={std::sin, std::cos, std::tan};
这个函数引用为什么出错???
我遇见一个问题。
error C2676: binary '!=' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type ac
#include "iostream"
#include "string"
using namespace std;
template<typename T>
T bianrysearch(T list[],T key,int arraysize)
{
int low=0;
int high=arraysize-1;
while (high>=low)
{
int mid=(low+high)/2;
if(key<list[mid])
high=mid-1;
else if(key == list[mid])
return mid;
else
low=mid+1;
}
return -low-1;
}
void main()
{
int a[]={1,2,3,4,5};
double b[]={1.2,2.3,3.4,4.5,5.6};
string str[]={"aaa","bbb","ccc","ddd","eee"};
cout<<bianrysearch(a,4,5)<<endl;
cout<<bianrysearch(b,4.5,5)<<endl;
cout<<bianrysearch(&str,"ccc",5)<<endl;
}
error C2782: 'T __cdecl bianrysearch(T [],T,int)' : template parameter 'T' is ambiguous
could be 'char *'
or 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > [5]'
求高手指点