Passing function pointer (error C3867)

I am reading values from a file into a single linked list then I'm supose to insert each value into a double linked list in ascending order. My double linked list is fully functional but I can not seem to figure out how to pass my double list append funtion into my single list traverse function.

I will include my working double list insert function, my single list traverse function and my print function from main.

main.cpp print function:

1
2
3
4
5
template <typename T>
void print(T val)
{
     cout << val << endl;
}




single link list traverse function:
1
2
3
4
5
6
7
8
9
10
11
template <typename T>
void List<T>::traverse(void (*visit)(T &val))
{
	Node<T> *temp = head;
	
	while(temp != NULL)
	{
		(*visit)(temp->value);
		temp = temp->next;
                }
}




double linked list insert function:
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
template <typename T>
void DoublyList<T>::insert(T val)
{
	Node *newNode, *nodePtr, *previousNode;
	newNode = new Node;
	newNode->value = val;

    // Insertion into an Empty List.
    if(!head)
    {
       head = newNode;
       newNode->prev = NULL;
       newNode->next = NULL;
	   count++;
    }
    else //otherwise insert node into existing list
    {
                   nodePtr = head;
	   previousNode = NULL;

	   //cycle through the list
	   while( nodePtr != NULL && nodePtr->value < val )
	   {
		   previousNode = nodePtr;
		   nodePtr = nodePtr->next;
	   }

	   if (previousNode == NULL)
	   {
		   head = newNode;
		   newNode->next = nodePtr;
		   newNode->prev = NULL;
		   count++;
	   }
                  else
                  {
		   previousNode->next = newNode;
		   newNode->next = nodePtr;
		   newNode->prev = previousNode;
		   count++;
	  }
    }
}
 



This is how I pass the print function to my single list traverse function:
 
  singleList.traverse(print);




when I try to pass my double list insert function
 
  singleList.traverse(doubleList.insert);




I get this error: error C3867:
'DoublyList<T>::insert': function call missing argument list; use '&DoublyList<T>::insert' to create a pointer to member.

I have done some searching but am at a loss on how to fix this. Any suggestions would be appreciated!
I believe you need to specify the template syntax to the argument:

 
singleList.traverse( doubleList<T>.insert );
1
2
3
template <typename T>
void List<T>::traverse(void (*visit)(T &val))
{

The prarameter for this function is just a standard C++ functiion pointer (which is good for
pointers to non_member_ function, and pointers to static_class_member_function).

You will need to overload it to take a class member funtion pointer if you want to use it
with the DoublyList<T>::insert function.
I tried to overload but kept getting very an error. Im afraid im trying to do something beyond the scope of my understanding atm.
Topic archived. No new replies allowed.