Question
Weird error. undefined reference to `quicksort::swapListValues(int*, int, int)' UPDATE : I found and fixed my error. It was a dumb mistake and I figured it
Weird error. undefined reference to `quicksort::swapListValues(int*, int, int)'
UPDATE : I found and fixed my error. It was a dumb mistake and I figured it out
Heres my code. The function in my class is suppose to swap two values in an array. But I am suppose to be able to run this code.
I also put where I get the error in my main function. If you find out the error please share a screenshot of your working program
class quicksort { private: int left; int right; int array[]; //I'm not sure if this is right or not. Change if necessary public: void swapListValues(int* array, int left, int right );
};
//This is the function that I was suppose to write
void swapListValues(int* array, int left, int right )
{
int temp = array[left];
array[left] = array[right];
array[right] = temp;
}
//Don't need to touch this
string tostring(int list[], int length) { ostringstream out;
out << "List length: " << length << " ["; if (length >= 1) { out << list[0]; } for (int index = 1; index < length; index++) { out << ", " << list[index]; }
out << "]";
return out.str(); }
//Don't need to touch this
bool listsAreEqual(int a[], int b[], int length) { for (int index = 0; index < length; index++) { if (a[index] != b[index]) { return false; } } return true; }
int main(int argc, char** argv) { // variables used for the function/unit tests const int MAX_TEST_SIZE = 100; int testvals[MAX_TEST_SIZE]; int expected[MAX_TEST_SIZE]; int length; quicksort sortAndSearch; // test of swap function ------------------------------------------------ cout << "Test swapListValues() ------------------------------------------" << endl;
// basic test length = 2; memcpy(testvals, (const int[]){5, 10}, sizeof(int) * length); memcpy(expected, (const int[]){10, 5}, sizeof(int) * length); sortAndSearch.swapListValues(testvals, 0, 1); //This is where the error is cout << "sortAndSearch.swapListValues() test 1, swap 2 values" << endl; << " expected: " << tostring(expected, length) << endl; << " actual : " << tostring(testvals, length) << endl; << endl; assert(listsAreEqual(testvals, expected, length));
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started