为什么本地定义的函数void List::traverse(ACCESSFUN f)不合法啊
maori 2011-04-28 04:41:27 为什么本地定义的函数void List::traverse(ACCESSFUN f)不合法啊?
代码如下:
//list.h
#ifndef __LIST__
#define __LIST__
#include "quad.h"
typedef void (*ACCESSFUN)(QUADPTR);
struct Node
{
QUADPTR data;
Node *next;
};
class List
{
private:
Node *head, *tail;
public:
List();
List(const List& l);
~List();
void push_back(const QUADPTR quad);
void traverse(ACCESSFUN f);
};
#endif
//end of list.h
//list.cpp
#include <iostream>
#include <string>
using namespace std;
#include "list.h"
List::List() : head(NULL), tail(NULL) {}
List::List(const List& l) : head(l.head ), tail(l.tail ) {}
List::~List()
{
Node *p = head, *q;
while (p != NULL)
{
q = p;
p = p->next;
delete q;
}
}
//insert element into the tail of list
void List::push_back(const QUADPTR quad)
{
Node *p,*q;
p=head;
while(p!=NULL)
{
if(q)
{
q->data=quad;
tail->next = q;
q->next=NULL;
q = tail;
}
}
void List::traverse(ACCESSFUN f)
{
Node *p=head;
while (p != NULL)
{
f(p->data);
p = p->next;
}
}