delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/06/10:47:12

Message-ID: <393CAD2A.7DD65072@gmx.de>
From: Ole Reinartz <ole DOT reinartz AT gmx DOT de>
Organization: Nokia
X-Mailer: Mozilla 4.06 [en] (WinNT; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: template error
References: <39190F26 DOT 609A37C8 AT home DOT com> <391C05F1 DOT 1AF32F2D AT gmx DOT de> <391C2047 DOT 57740096 AT home DOT com>
Lines: 46
Date: Tue, 06 Jun 2000 07:45:21 GMT
NNTP-Posting-Host: 172.25.108.216
X-Complaints-To: newsmaster AT nokia DOT com
X-Trace: news1.nokia.com 960277521 172.25.108.216 (Tue, 06 Jun 2000 10:45:21 EET DST)
NNTP-Posting-Date: Tue, 06 Jun 2000 10:45:21 EET DST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com


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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019