0

Hi,
This is the code segment:

template<class type> void merge_sort(type inputs[], int p, int r, int (*comp)(type, type));

typedef struct
{
	vertex vertices[MAX_VERTEX];
	int number_vertices;
	int adj_matrix[MAX_VERTEX][MAX_VERTEX];
} graph;

int compare_vertex(vertex v1, vertex v2) 
{
	if (v1.f < v2.f)
	{
		return -1;
	}
	else if (v1.f > v2.f)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main() {
        graph* g; 
        int (*cmp)(vertex v1, vertex v2);
	cmp = compare_vertex;
	int num_vertices = g->number_vertices;
	merge_sort<vertex>(g->vertices, 0, num_vertices, cmp);
}

Why am I still getting no matching function? because as observed from the declaration of merge_sort it takes an array of template type, 2 int, 1 pointer to a function having 2 arguments of type. In the calling routine the merge_sort is called with template type vertex with arguments- an array of vertices, 2 int, and a function pointer taking 2 arguments of type vertex.

Thanks.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mitrmkar
0

Are you sure you posted a relevant code snippet? The error message says:

error: no matching function for call to ‘merge(vertex*&, int&, int&, int&)

So there should be a call to merge(...) , but there isn't.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.