0
votes

All I am trying to do is make a set of pairs given a relation. I keep getting the following error from line 208 in file xmemory:

error C2664: 'std::pair<_Ty1,_Ty2>::pair(std::pair<_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'std::pair<_Ty1,_Ty2> ' to 'std::pair<_Ty1,_Ty2> &' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xmemory 208

I am not sure why, here is my code:

void print_relation(const set<pair<int, int>> R);
set<pair<int, int>> init_relation(const int A[], const int size);

void main()
{
   int A[] = {1, 4, 5, 7, 8, 13, 18, 22, 39};
   const int size = 9;

   set<pair<int, int>> R = init_relation(A, size);
   print_relation(R);

   system("pause");
}

void print_relation(const set<pair<int, int>> R)
{
   set<pair<int, int>>::iterator Rit = R.begin();

   cout << "Relation R:" << endl << endl;

   for(int i = 0; Rit != R.end(); Rit++, i++)
   {
        printf("%d: (%d, %d)\n", i, (*Rit).first, (*Rit).second);
   }
}

set<pair<int, int>> init_relation(const int A[], const int size)
{
   set<pair<int, int>> R;

   for(int i = 0; i < size - 1; i++)
   {
       for(int j = 0; j < size - 1; j++)
       {
               if( (A[i] - A[j]) % 7 == 0 )
           {
                    R.insert(new pair<int, int>(i, j));
           }
       }
   }

   return R;
}
1
Tell us what line of your code is affected.John Zwinck

1 Answers

4
votes

Error is here

R.insert(new pair<int, int>(i, j));

You should insert pair not pointer to pair.

R.insert(pair<int, int>(i, j));