【发布时间】:2014-06-11 06:38:05
【问题描述】:
代码中有两种类型的错误,基于 向量 > vg(n) 我无法纠正
- 在最后一行,即; return 0 语句有一个错误,说“模板参数的数量错误(1,应该是 2)|和一个 Line:87 链接到 STL 库,上面写着“提供给‘template struct std::pair”
- 函数的第一行(第 7 行)表示模板参数无效
#include <utility>
#include <cmath>
#include<cstdio>
#include <vector>
using namespace std
#define COMP(a,b,xx,yy)(sqrt(((a-xx)*(a- xx)) + ((b-yy)*(b-yy))))
double radius ( vector<pair<(int, int)> > vk, int ii, int n)
{ //error:template argument 1,2 is invalid
int d=n;
int xx=vk[ii].first;
int yy=vk[ii].second;
int k = ii==0? 1:0;
double small=COMP(vk[k].first,vk[k].second,xx,yy);
double dd;
for (int i=0;i<d; i++)
{
if (i!=ii)
dd=COMP(vk[i].first,vk[i].second,xx,yy);
{
if (small>dd)
small=dd;
}
}
return small;
}
int main()
{
int t,n=1;
int k=0;
double r,l;
//Enter the value of t
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);// Enter the value of n
vector <pair <int, int> > vg(n);
for (int i=0; i<n; i++)
{
scanf("%i %i",&vg[i].first,&vg[i].second);
//Enter the value of x and y co-odinates
}
for (int i=0; i<n; i++)
{
r=radius(vg,i,n);
l= (round(r*100.00))/100.00;
printf("%g\t%i\n",l);
}
}
return 0;
/* Error: wrong number of template arguments (1, should be 2)|
provided for ‘template<class _T1, class _T2> struct
std::pair’|*/
}
【问题讨论】:
-
请缩进你的代码
标签: c++ templates vector stl std-pair