1

There are 2 types of errors in the code based on vector > vg(n) which i am unable to rectify

  1. In the last line i.e.; the return 0 statement has an error saying "wrong number of template arguments (1, should be 2)|and a Line:87 link to the STL library which says "provided for ‘template struct std::pair"
  2. The first line of the function (line 7) says that the template arguments are invalid

 #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’|*/ 
  }
101010
  • 41,839
  • 11
  • 94
  • 168
APD
  • 159
  • 2
  • 12

3 Answers3

0

It should be std::vector<std::pair<int, int> >, although I don't see why you are passing it by value instead of by const reference.

D Drmmr
  • 1,223
  • 8
  • 15
  • I have included "using namespace std;" Hence i didnt prefix it with std :: . Also i tried passing it by value in a previous program and it gave me the desired output. – APD Jun 11 '14 at 13:54
  • See: http://stackoverflow.com/questions/270408/is-it-better-in-c-to-pass-by-value-or-pass-by-constant-reference – D Drmmr Jun 11 '14 at 17:50
0

In your function declaration, remove the parenthesis around the vector template type:

double radius ( vector<pair<int, int> > vk, int ii, int n)

A few notes :

  • Always check the return value of scanf
  • Avoid passing vectors by value around
  • Prefer C++ iostreams to C-style printfs/scanf
  • Replace the COMP macro by an inline function
  • Properly indent your code
quantdev
  • 23,517
  • 5
  • 55
  • 88
  • IT WORKED !! The removal of a single pair of parenthesis was the solution!!!! It worked in an earlier code so i tried passing it by value again. I used C-style printfs/scanf since it reduces the time taken. I'll definetly implement the last 2 suggestions. THANK YOU – APD Jun 11 '14 at 14:01
0

I see the following problems:

One

using namespace std

There's a missing ;. It should be

using namespace std;

Two

double radius ( vector<pair<(int, int)> > vk, int ii, int n)

should be

double radius ( vector<pair<int, int> > vk, int ii, int n)

Three

printf("%g\t%i\n",l);

You have two format specifiers but only one value is being passed to the function.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • The ; was there in the original code. THANK YOUUU, I removed the parenthesis and my code compiled. In the printf part, also the mistake isnt present in the original code – APD Jun 11 '14 at 14:04
  • @KrisnaTaapad So why didn't you post your original code? Does your editor not support copy-paste? – D Drmmr Jun 11 '14 at 17:47
  • It was a long program so i had to make some modifications to it so as to post only the relevant part here. By mistake, i didn't modify those parts. – APD Jun 12 '14 at 04:34