Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!gatech!bbn!oberon!stromboli.usc.edu!english
From: english@stromboli.usc.edu (Joe English)
Newsgroups: comp.lang.c++
Subject: Two questions
Summary: static members, automatic temporaries
Message-ID: <13683@oberon.USC.EDU>
Date: 28 Nov 88 06:50:12 GMT
Sender: news@oberon.USC.EDU
Reply-To: english@stromboli.usc.edu (Joe English)
Distribution: na
Organization: University of Southern California, Los Angeles, CA
Lines: 66


   In the Book, section 8.5.1 (Static Members), p. 275, it states:
"No initializer can be specified for a static member, and __it cannot
be of a class with a constructor__."  I'm not sure if I'm parsing this
sentence correctly: does it mean that a class with a constructor can
have no static members?  Also, if no initializer can be specified,
where and how does a static member get initialized?


  Second question:  if automatic temporary objects are created when
necessary and are destroyed at the first opportunity (like when a
function returns a class object), how does the compiler know when the
object is no longer needed?  For example, is the following correct:

(What I want to happen is for the addresses of the (automatic) frobs
created by the calls to frob::frob(int) to be stored in v, and for the
frobs themselves to *remain intact* for the life of the function.)


class frob {
...
public:
    frob(int) {...}
};

class frobpvector {           // a vector of pointers to frobs
  frob *list[MAX];
  frob **next;
public:
  frobpvector() { next = list; }
  void append(frob&);
};


void frobpvector::append(frob& f)  { *next++ = &f; }

void diddle() 

{
    frobpvector v;

    v.append(frob(1));     //  frob(1) returns a temporary
    // ... 
    v.append(frob(2));     //  frob(2) should be a *different* frob

    // ... do stuff with the frobs pointed to in v 

}


In other words, if an automatic temporary object is passed to a
function as a reference parameter, _is the space allocated to that
temporary object guarranteed to not be overwritten in the current
scope_?

This is probably in TFM, but I cannot for the life of me find where it
is explicitly stated.  I need to know for sure, or else I will have to
rethink an important class interface.

BTW, Zortech C++ seems to be doing (what I feel is) the right thing
here.


      /|/| "How do you convince your dermatologist 
-----< | |                      that you're being sexually responsible?
  O   \|\| english%lipari@oberon.usc.edu  (Joe English)