www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/23/16:35:30

From: Thomas Matthews <matthto AT atlantis DOT stortek DOT com>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp,comp.programming
Subject: Re: Question: Linked lists and classes: Self initiation
Date: Fri, 23 Apr 1999 14:03:40 -0600
Organization: StorageTek Corporation
Lines: 38
Message-ID: <3720D21C.9617323B@atlantis.stortek.com>
References: <3720BE52 DOT 6E86A8C4 AT xoommail DOT com>
NNTP-Posting-Host: tourmaline.stortek.com
Mime-Version: 1.0
X-Trace: news.stortek.com 924897820 20511 129.80.193.2 (23 Apr 1999 20:03:40 GMT)
X-Complaints-To: news AT stortek DOT com
NNTP-Posting-Date: 23 Apr 1999 20:03:40 GMT
X-Mailer: Mozilla 4.05 [en] (X11; I; SunOS 5.6 sun4u)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ishpeck wrote:
> 
> Is it fezible to have a linked list initiate itself recursively?  I
> think the best way to describe what I'm trying to say is put some
> code up...
> 
> class fooclass {
>   int number;
>   char character;
>   fooclass *next;
>   public:
>   void init(int setnum, char setchar, int quantity) {
>     number = setnum;
>     character = setchar;
>     if(quantity>0){
>       next = new(fooclass);
>       next.init(setnum, setchar, quantity-1);
>     }//end if
>   }//end init method
> };//end class

I don't understand.  How can initialization be recursive when initialization
occurs once?

Try this:
   fooclass(int setnum = 0, /* or a default value */
            char setchar = 0, /* or a default value */
            quantity = 0)
   : number(setnum), character(setchar), next(NULL)
   {
   }

I don't see how your init function relates to a linked list.  Is it creating
another node? another list?  inserting an element?

-- 
Thomas Matthews
email: matthto AT stamps DOT stortek DOT com

- Raw text -


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