Question:
Undefined reference, C++?
Cassi
2013-05-30 17:32:58 UTC
When attempting to compile my program, I get an error of "undefined reference to search (char, int, int, int)'. Below is a portion of the program I am writing for my project, so any input on what I may have done wrong would be greatly appreciated. This seems to be my only issue right now with it, and it's anything like my last question it's an obvious mistake I'm missing.

#include // cin/cout
#include // stream
#include // setw
using namespace std;

void search (char, int, int, int);

int main ()
{
int i = 0;
int SIZE = 0;
char numbers[50];
int tally[50];
int source, num;
char file_name[16];

do
{
cout << "Enter 1 for manual input from keyboard, 2 for reading from a file: ";
cin >> source;
} while (!((source == 1) || (source == 2)));
if (source == 1) // keyboard
{
do
{
cout << "Enter a number (99999 to end): ";
cin >> num;
search (numbers[i], tally[i], num, SIZE);
} while (num != 99999);
}
}


void search (char numbers[], int tally[], int target, int SIZE)
{
int index = 0;
bool found = false;
while ((!found) && (index < SIZE))
{
if (target == numbers[index])
found = true;
else
index++;
}
if (found)
{
tally[index]++;
}
else
{
numbers[SIZE] = target;
tally[SIZE] = 1;
SIZE++;
}
return;
}
Three answers:
2013-05-30 17:34:41 UTC
change: void search (char, int, int, int);

may be: void search (char*, int*, int, int);
mansharam
2016-11-07 03:38:33 UTC
you have an unused parameter on your function implementation (double variety) that isn't contemplated in the definition. when you consider that i will see which you're new to programming, i will tricky. The undefined reference function only potential that, while your software tries to execute "opposite(GPA, length)", it recollects which you declared a function named "opposite(double, int)", yet while it seems for the relatively implementation, it would not discover it via extra advantageous parameter and somewhat reads it as a diverse function altogether.
Dan
2013-05-30 18:13:11 UTC
Could it be that you're calling a method which you've defined to have no method body?



Are you intending to call the method which requires you to pass an array of characters, an array of ints, and int, and an int? That one has a body, but the other (char, int, int, int) doesn't.



Dunno.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...