Question:
undefined reference in c++?
Sariss
2010-12-11 08:12:34 UTC
I'm getting an error reading this

undefined reference to `reverse(double*, int)'
collect2: ld returned 1 exit status

My codes concerning the reverse are...

void reverse(double array[], int size);
//This funciton receives an array and its size.
//The function reverses the order of all elements in the array.
//For example, if array=[6,2,5,3,4], the funciton changes it to array=[4,3,5,2,6].
.
.
.
.
//Reverse the GPA list.
reverse(GPA, size);

//Output the reversed list.
cout<<"GPA list after reversing"<.
.
.
.
.
.
void reverse (double array[], int size, double number)
{
for (int i=0; i <= size; i++)
{
swap( array[i], array[0]);
}
}
.
.
.
.
.
What does the error mean? How do I correct it?
Six answers:
Silent
2010-12-11 08:18:50 UTC
Look at the function prototype, and look at the function definition.



Do they have the same parameters?
?
2017-01-20 09:04:55 UTC
1
2010-12-11 08:25:14 UTC
You have an unused parameter in your function implementation (double number) that is not reflected in the definition.



Since I can see that you are new to programming, I will elaborate. The undefined reference function simply means that, when your program tries to execute "reverse(GPA, size)", it remembers that you declared a function named "reverse(double, int)", but when it looks for the actual implementation, it does not find it because of the extra parameter and instead reads it as a different function altogether.
Amit Kumar
2010-12-11 08:43:01 UTC
in the reverse function you have defined two parameters but using it through three parameters .



since you have define function as void reverse(double array[], int size) which have two parameters but your calling this function as reverse (double array[], int size, double number) which have three parameters .
2016-10-20 16:21:44 UTC
might desire to it is which you're calling a means which you have defined to have no approach physique? Are you proceeding to call the tactic which calls so you might bypass an array of characters, an array of ints, and int, and an int? That one has a physique, however the different (char, int, int, int) would not. Dunno.
Afifah
2014-10-15 01:47:29 UTC
undefined reference to 'printf".....

i have already check spelling and it still appear this error notice...


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