Xref: utzoo comp.lang.c++:11516 gnu.g++.help:449 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!uunet!shelby!mcnc!duke!tan From: tan@duke.cs.duke.edu (Jit Keong Tan) Newsgroups: comp.lang.c++,gnu.g++.help Subject: How to link pointers together during declaration ? Keywords: constructor, linked-list initialization Message-ID: <665960512@romeo.cs.duke.edu> Date: 7 Feb 91 21:01:53 GMT Followup-To: poster Organization: Duke University Computer Science Dept.; Durham, N.C. Lines: 66 Subject: How to link pointers together during constructor declaration ? Is is possible to do the following: ===================================================== class linked_list { static int first=1; static linked_list *head; public: linked_list *next; linked_list() { if (first == 1) { first=0; next=NULL; head = ???? the declaration of the first element how to get the address ? } else { find the end of the list and link the current variable. how to get it ? } } }; During declaration, linked_list aa,bb; will automatically initialize aa.next = bb; bb.next = NULL; and sometime later in the code, linked_list *cc= new linked_list; will make it to aa.next = bb; bb.next = cc; cc->next = NULL; is it legal to do something like linked_list::linked_list(linked_list *aa) { head=aa; } linked_list aa(&aa); ? ===================================================== Please keep in mind that I am just starting C++ programming. So any suggestion, including a totally different way of implementing it (automatically) is very much appreciated. Thanks. -- ======================= internet: jit@slic.cellbio.duke.edu