Converting array to vector

I'm supposed to modify a code from array to vectors.
But the vector one won't work and it says undefined reference to.

The original code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;// Function Prototype
bool testPIN(const int [], const int [], int);
int main ()
{const int NUM_DIGITS = 7; 
int pin1[NUM_DIGITS] = {2, 4, 1, 8, 7, 9, 0};
int pin2[NUM_DIGITS] = {2, 4, 6, 8, 7, 9, 0}; 
int pin3[NUM_DIGITS] = {1, 2, 3, 4, 5, 6, 7};
if (testPIN(pin1, pin2, NUM_DIGITS))
cout << "ERROR: pin1 and pin2 report to be the same.\n";
else
cout << "SUCCESS: pin1 and pin2 are different.\n";
if (testPIN(pin1, pin3, NUM_DIGITS))
cout << "ERROR: pin1 and pin3 report to be the same.\n";
else
cout << "SUCCESS: pin1 and pin3 are different.\n";
if (testPIN(pin1, pin1, NUM_DIGITS))
cout << "SUCCESS: pin1 and pin1 report to be the same.\n";
else
cout << "ERROR: pin1 and pin1 report to be different.\n";return 0;}
//******************************************************************// The following function accepts two int arrays. The arrays are   *// compared. If they contain the same values, true is returned.    *// If the contain different values, false is returned.            *//******************************************************************
bool testPIN(const int custPIN[], const int databasePIN[], int size){
for (int index = 0; index < size; index++)
{if (custPIN[index] != databasePIN[index])
return false;
return true;
}


My work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Description: This program is a driver that tests a function comparing the// contents of two int arrays.

#include <iostream>

#include <vector>

using namespace std;

bool testPIN(vector<int>&,vector<int>&);

int main ()

{

    const int NUM_DIGITS = 7;

    int pin1[NUM_DIGITS] = {2, 4, 1, 8, 7, 9, 0};

    int pin2[NUM_DIGITS] = {2, 4, 6, 8, 7, 9, 0};

    int pin3[NUM_DIGITS] = {1, 2, 3, 4, 5, 6, 7};

    vector <int> vpin1(&pin1[0],&pin1[0]+7);

    vector <int> vpin2(&pin2[0],&pin2[0]+7);

    vector <int> vpin3(&pin3[0],&pin3[0]+7);

    if (testPIN(vpin1, vpin2))cout << "ERROR: pin1 and pin2 report to be the same.\n";

    else

        cout << "SUCCESS: pin1 and pin2 are different.\n";

    if (testPIN(vpin1, vpin3))cout << "ERROR: pin1 and pin3 report to be the same.\n";

    else

        cout << "SUCCESS: pin1 and pin3 are different.\n";

    if (testPIN(vpin1, vpin1))

        cout << "SUCCESS: pin1 and pin1 report to be the same.\n";

    else

        cout << "ERROR: pin1 and pin1 report to be different.\n";

    return 0;

}

bool testPIN(vector <int> &v1, vector <int> &v2, int size)

{

    if (v1 != v2)

        return false;

}
Last edited on
undefined reference to 'testPIN(std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&)'
undefined reference is on line 53 the ( int size )

HINT line 9 needs to be changed

HINT HINT you need to declare your ( int size ) on line 9
Last edited on
damn i didn't notice the int size it's not supposed to be there.
thanks a lot!
Topic archived. No new replies allowed.