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