I was writing up my NTree class that I need for a program that I'm working on. My function order() takes in a vector and a string and sorts the vector according to that string so the words closest to the string (one letter off) are at the beginning of the vector. This is the function.

vector <string> order (vector <string> vec, string start)
	{  vector <com> set (vec.size());
	   vector <string> nset (vec.size());
	   int x, diff;
	   for (x = 0; x < vec.size(); x++)
		   { diff = compare (vec[x], start);
			 set[x].data = vec[x];
			 set[x].num = diff; }
	   sort (set.begin(), set.end(), com_num);
	   for (x = 0; x < vec.size(); x++)
	       { nset[x] = set[x].data; }
       return nset;

My problem is that it doesn't like the sort call. Now, if I take this function out of my tree and place it with the actual program, it runs fine. The reason it gives is that com_num is an unknown type. This is what it is.

bool com_num (com i, com j) { return (i.num < j.num); }

Am I just missing something? How come it won't work in my tree class, but it will outside of it?

9 Years
Discussion Span
Last Post by DemonGal711

Where is the declaration of com_num in relation to the order function? com_num needs to be visible to any compile target that can see order.

What specifically is the compiler error?

Which is the line that generates the compiler error?


It doesn't really matter any more, I just worked around it.

Basically the compiler was saying something like:
error in line 'sort ( RandomAccessIterator first, RandomAccessIterator last, <unknown type>)'
expected 'sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp )'

This question has already been answered. 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.