How to define the function?

I keep getting 3 errors unresolved external symbol "void __cdecl showValues(int * const,int)" (?showValues@@YAXQAHH@Z) referenced in function _main. I looked up the error and from what I've found it means I have declared but not defined the function. Not sure how to define the function, any help would be appreciated. The purpose of this program is to search sort and display an array of 3 different data types.
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* preprocessor statements ***********************************/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

/* prototype for template functions (global) *****************/
// CODE BEGINS
template < class T >
void showValues( T values[], int SIZE );

template < class T >
void doubleArray( T values[], int SIZE );

template < class T >
void sortArray( T values[], int SIZE );

// STUDENT CODE ENDS (template prototypes)

/* application entry point ***********************************/
int main()
{
/* declarations section ************************************/
// Function prototypes (other than templates)
void showValues( int [], int );
void doubleArray( int [], int );
void sortArray( int [], int );

// declare arrays and data here
// use a size declarator
// CODE BEGINS
const int SIZE = 7;
int values[SIZE] = {6,2,3,5,9,2,1};
unsigned short int uvalues[SIZE] = {250,100,34000,5000,298,12,20123};
long double lvalues[SIZE] = {1.432,12.5432,1.422,3.1234,3.111,4.3321,5};

// STUDENT CODE ENDS

string programLoop = "Y";
int menuChoice;

/* statements section **************************************/

do
{

// menu
cout << "0 - exit\n";
cout << "Enter your choice: ";
cin >> menuChoice;

// do it! - expand 'switch' as you complete each method
// STUDENT CODE BEGINS
switch (menuChoice)
{
case 0:
programLoop = "N";
break;
case 1:
showValues( values, SIZE ); // show int array values
break;
case 2:
showValues( values, SIZE ); // show unsigned short int values
break;
case 3:
showValues( values, SIZE ); // show long double values
break;
case 4:
doubleArray( values, SIZE ); // double the int array values
break;
case 5:
doubleArray( values, SIZE ); // double the unsigned short int values
break;
case 6:
doubleArray( values, SIZE ); // double the long double values
break;
case 7:
sortArray( values, SIZE ); // sort int values
break;
case 8:
sortArray( values, SIZE ); // sort unsigned short values
break;
case 9:
sortArray( values, SIZE ); // sort long double values
break;
default:
cout << "Invalid selection - try again\n\n";
}
// CODE ENDS

} while (programLoop == "Y");

/* termination section *************************************/
cin.get();
return 0;
}


/**************************************************************
Function definition: doubleArray
Parameter(s): numbers[] : T, size : int
Returns: void

This function doubles the value of each element
in the array passed into nums. The value passed
into size is the number of elements in the array.
**************************************************************/
// STUDENT CODE BEGINS
template < class T >
void doubleArray( T values[], int SIZE)
{ for (int index = 0; index < SIZE; index++)
{
values[index] *= 2;
}
}

// CODE ENDS


/**************************************************************
Function definition: showValues
Parameter(s): numbers[] : T, size : int
Returns: void

This function accepts an array of integers and
the array's size as its arguments. The contents
of the array are displayed.
**************************************************************/
// CODE BEGINS
template < class T >
void showValues( T values[], int SIZE )
{
for ( int index = 0; index < SIZE; index++)
{
cout << right << setw(10) << values[index];
}
cout << endl;
}

// STUDENT CODE ENDS


/**************************************************************
Function definition: sortArray
Parameter(s): numbers[] : T, size : int
Returns: void

Sort type: selection sort
Order: ascending or descending, your choice
**************************************************************/
// CODE BEGINS
template < class T >
void sortArray( T values[], int SIZE )
{
/***Local Identifiers***/
bool swap; // true = swap took place
T temp; // holds value for swapping

do
{
swap = false;
for ( int index = 0; index < ( SIZE - 1 ); index++ )
{
if ( values[index] > values[index + 1] )
{
temp = values[index];
values[index] = values[index + 1];
values[index + 1] = temp;
swap = true;
}

}
} while (swap);
}


Last edited on
CisntEZ wrote:
I looked up the error and from what I've found it means I have declared but not defined the function. Not sure where I am going wrong

That's exactly what you did, and that is indeed wrong.
Here that non-template function taking a pointer to int and an int was declared:
1
2
// Function prototypes (other than templates)
void showValues( int [], int );
And it was never defined.

There are other errors, by the way, try compiling with gcc or clang; e.g. http://coliru.stacked-crooked.com/a/a0dc7835e112132a or http://coliru.stacked-crooked.com/a/9fa1da1e38f13eb6
Last edited on
But i am a confused on how to define it. Would this be like void showValues( int [], int ) = values;
or void showValues( int values [], int SIZE ); ?
Both give me errors. Thank you. And I like those compilers I will give them a try.
I also updated the code above fixing other errors. All that is left is the defining the functions.
But i am a confused on how to define it.

Why do you want it at all? There is a showValues at line 131. Is the intended behavior for int arrays going to be different from what the generic version at line 131 does?

If it's not intended to be different then don't declare (and don't define) another function with the same name.
no it is not. I included it because we have just began learning about templates and an example code had it as well. But, even commenting out lines 25-27 gives 3 similar errors each for one of the functions like " Error 5 error LNK2019: unresolved external symbol "void __cdecl sortArray(int * const,int)" (?sortArray@@YAXQAHH@Z) referenced in function _main "
I just got it. You were correct thank you very much for the help!
Topic archived. No new replies allowed.