home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18362 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.3 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!haven.umd.edu!news.umbc.edu!umbc8.umbc.edu!reagle
  3. From: reagle@umbc8.umbc.edu (Mr. Joseph Reagle; MEYERHOFF (U))
  4. Subject: Do I need to worry about what the compiler will do?
  5. Message-ID: <1992Dec23.203258.26281@umbc3.umbc.edu>
  6. Sender: newspost@umbc3.umbc.edu (News posting account)
  7. Organization: University of Maryland, Baltimore County Campus
  8. Date: Wed, 23 Dec 1992 20:32:58 GMT
  9. Lines: 42
  10.  
  11.     I've been considering writing a C++ linked list, and then
  12. develop a class queue and class stack based on the linked list.
  13. Within the book I have been reading (Turbo C/C++ (with Borland) the Complete
  14. Reference)) there is a simple example of a linked list using a
  15. template.
  16.     I unfortunately don't have the book with me right now,
  17. (waiting for pop to take me home, and the books are packed, but I can
  18. type in the example once I get home), but essentially it is a simple
  19. linked list using a template so it can take any: 
  20.     data_t data
  21.     linked_list *next,
  22. then within the class public functions such as add are in there, the
  23. add I believes looks something like this:
  24.     add (linked_list *node) {node->next = this;}
  25.  
  26. and within the main body, a pointer to an object name "last" is passed
  27. in.
  28.     Now to the real question, each node in this linked list is
  29. made by passing in a every char in the alphabet in as part of the
  30. constructer: (p is a pointer to the object list as well.)
  31.  
  32. while (i < 26) loop
  33.     Make P point to a new iniatized object (node) [constructer used]
  34.     p->add (last)
  35.     i++
  36.  
  37.     _So_ my question is, since each node is actually an object,
  38. with it's own data, all created when the constructor
  39. is called, and dynamic iniatilization is used to pass in a char, does
  40. each one of those nodes (objects)  also contain, or cause the compiler
  41. to create it's own function.  (So for however many instances of objects from
  42. the same class, there are an equal amount of 'functions' in the
  43. executable code, all exactly similar in what they do.)
  44.     I would assume not, but if not, does it only 'compile' one
  45. instance of the function?
  46.     If you don't understand what I've said here, don't worry, when
  47. I get home, I'll post the source code that led me to the question.
  48. And I'm sure it's a very simple answer, for if the compile were to
  49. duplicate similar (exactly) functions that may reside in 2 or more
  50. objects the binary image would be much larger than it has to be.
  51.  
  52.                     Joe
  53.