Instantiated from here error

I'm working on this code, and when I try to compile the program. I keep getting the error "instantiated from here". The lines the compiler says that the problem is coming from is in bold and underlined in the code below.

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
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include "sorts.h"
#include "quicksort.h"

using std::cout;
using std::fixed;
using std::left;
using std::setprecision;
using std::string;
using std::vector;

// Data files

#define D1 "C:\\Users\\Omar\\Documents\\CSCI 241\\data8a.txt"
#define D2 "C:\\Users\\Omar\\Documents\\CSCI 241\\data8b.txt"
#define D3 "C:\\Users\\Omar\\Documents\\CSCI 241\\data8c.txt"

// Output formatting constants

#define INT_SZ 4    // width of integer
#define FLT_SZ 7    // width of floating-pt number
#define STR_SZ 12   // width of string

#define INT_LN 15   // no of integers on single line
#define FLT_LN 9    // no of floating-pt nums on single line
#define STR_LN 5    // no of strings on single line

int main()
   {
   vector<int> v1;      // vector of integers
   vector<float> v2;    // vector of floating-pt nums
   vector<string> v3;   // vector of strings

   // Print header message
   cout << "*** CSCI 241: Assignment 8 - Part 2 Output ***\n\n";

   // sort and print first list

   cout << "First list - ascending order:\n\n";
   buildList(v1, D1);
   quickSort(v1, &lessThan);
   printList(v1, INT_SZ, INT_LN);

   // Sort and print second list

   cout << fixed << setprecision(2);

   cout << "\nSecond list - descending order:\n\n";
   buildList(v2, D2);
   quickSort(v2, &greaterThan);
   printList(v2, FLT_SZ, FLT_LN);

   // Sort and print third list

   cout << left;

   cout << "\nThird list - ascending order:\n\n";
   buildList(v3, D3);
   quickSort(v3, &lessThan);
   printList(v3, STR_SZ, STR_LN);

   // print termination message
   cout << "\n*** End of program execution ***\n";

   return 0;
   }


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
#ifndef SORT_H
#define SORT_H
#include <fstream>
using namespace std;

template <class T>
void buildList(vector<T>& set, const char* fileName)
	{
	T item;
	ifstream inFile;

	inFile.open(fileName);
	if (!inFile)
		{
		cout << "Error - unable to open input file " << fileName << endl;
		}
	inFile >> item;	
	while (inFile)
		{
		set.push_back(item);
		inFile >> item;
		}
	inFile.close();  
	}

template <class T>
void printList(const vector<T>& set, int itemWidth, int numPerLine)
	{
	for (int i = 0; i < set.size(); i++)
		{
		cout << setw(itemWidth) << right << set[i] << ' ';
		
			if ((i+1) % numPerLine == 0)
				cout <<endl;
		}
	}

template <class T>
bool lessThan(const T& item1, const T& item2)
	{
	if (item1 < item2)
		return true;
	else
		return false;
	}

template <class T>
bool greaterThan(const T& item1, const T& item2)
	{
	if (item1 < item2)
		return true;
	else
		return false;
	}
	
#endif 


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
#ifndef QUICKSORTS_H
#define QUICKSORTS_H
using namespace std;

template <class T>
void quickSort(vector<T>& set, bool (*compare)(const T&, const T&))
	{
	quickSort(set, 0, set.size()-1, compare);
	}
	
template <class T>
void quickSorts(vector<T>& set, int start, int end, bool (*compare)(const T&, const T&))
	{
	int pivotPoint;
	
	if (start < end)
		{
		pivotPoint = partition(set, start, end, compare);     // Get the pivot point
		quickSort(set, start, pivotPoint - 1, compare);       // Sort first sublist
		quickSort(set, pivotPoint + 1, end, compare);         // Sort second sublist
		}
	}
	
template <class T>
int partition(vector<T>& set, int start, int end, bool (*compare)(const T&, const T&))
	{
	int pivotIndex;
	int mid;
	T pivotValue;
	
	mid = (start + end) / 2;
	
	swap (set[start], set[mid]);
	
	pivotIndex = start;
	pivotValue = set[start];
	
	for (int scan = start + 1; scan <= end; scan++)
		{
		if (compare(set[scan], pivotValue))
			{
			pivotIndex++;
			swap (set[pivotIndex], set[scan]);
			}
		}
	
	swap(set[start], set[pivotIndex]);
	
	return pivotIndex;
	}
	
#endif 
This is two-lines error. Please post the first line, where you are told what the error is. I suppose that compiler cannot deduce type T. Try to use your function like: quicksort<int>(v1, &lessThan);
Last edited on
The error said in function
'void quickSort(std::vector<T, std::allocator<_CharT> >&, bool(*)(const T&, const T&))[with T = int]':
in vectorsort.cpp:44 instantiated from here

no matching function for call to quickSort(std::vector<T, std::allocator<_CharT> >&, int, unsigned int, bool(*&)(const T&, const T&))[with T = int]':
Last edited on
a) Line 12 of Quicksort.h function called quickSorts() and you calling quickSort() on line 6
b) You again calling quickSort() in quickSorts() function
c) quickSorts() declared after quickSort() and partition() declared after quickSorts() which uses each other. either reverse their order or do a forward declaration.

d) NEVER use using in headers. You might use it implementation (however it is a bad practice) but never use it in headers. For example statements on lines 8-13 of main have no effects because using namespase std; is in effect. Guess where it happens.
Topic archived. No new replies allowed.