Mail Archives: djgpp/2000/06/06/10:47:12
Robin Johnson wrote:
> I am currently writing a templated tree system that I need,
> and it needs to be able to do traversal via a callback mechinism.
>
> template<class tItem>
> void traverse_pre(tNode<tItem> *tree,tCallBack<tItem> Visit)
> { if(!tree) return;
> Visit(tree);
> traverse_pre(tree->left);
> traverse_pre(tree->right);
> }
>
> Ole Reinartz wrote:
> >
> > Robin Johnson wrote:
> >
> > > I am getting an error that I am at a complete loss to explain...
> > > The g++ FAQ mentions nothing like it, so I thought I'd ask just to be sure...
> > >
> > > Error: template declaration of `typedef void ( tCallBack)(struct tNode<tItem>
> > > *&)'
> > >
> > > Code Segment:
> > > template <class tItem>
> > > struct tNode {
> > > tItem data;
> > > tNode *right, *left;
> > > };
> > >
> > > template <class tItem>
> > > typedef void tCallBack(tNode<tItem>* &node); //error here
Robin,
Now I see better (I hope). Now what should tCallBack be? A function pointer to a
function which takes a tNode<tItem> object and returns nothing?. Hm...
So you need a pointer to a template function. No easy... Have a look at this:
http://www.bestweb.net/~rhickey/functor.html
It is something about 'template functors' which sounds very near to what you need.
Hope this helps,
Ole
- Raw text -