From -2848588570921019420
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,924f354765fe932a,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-17 10:44:01 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: korpela@ellie.ssl.berkeley.edu (Eric J. Korpela)
Newsgroups: comp.std.c++
Subject: constructor calls in vectors
Date: Fri, 17 May 2002 17:43:16 GMT
Organization: Cal Berkeley-- Space Sciences Lab
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <ac1iu6$222i$1@agate.berkeley.edu>
X-Trace: mail2news.demon.co.uk 1021657405 mail2news:8785 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
NNTP-Posting-Date: Fri, 17 May 2002 00:29:58 +0000 (UTC)
X-PGP-ID: FF0C92DD
X-PGP-Fingerprint: 96 BD 9D 77 12 FE 04 9B  3E F5 5B 8D 2D D1 4C 6B
Lines: 48
Xref: archiver1.google.com comp.std.c++:11344

Quick (or maybe not so quick) std::vector question.  Does the
standard specify what constructors will be called during creation
of a vector?  For example when I have classes like the following...

class A {
  public:
    int i;
    A();                  // Constructor:  Details left to the imagination
    A(const A &a);        // Copy Constuctor:  Ditto
};

int main(void) {
  std::vector<A> B(1024));
}
  
My problem is in porting some code between two platforms.  On one platform
the A() constructor is called for every element.  On the other, the A()
constructor is called once and the copy constructor is used to transfer
its value to the other elements of the vector.  For most initializations
this wouldn't be a problem.  However, in this case the vector is an
initial state vector for a Monte Carlo simulation.  The A() constructor
is used to build the initial state.  As the copy constructor is used
elsewhere, I can't easily change its definition to mimic the constructor.

At any rate, the questions are...  Is either of these compilers doing
something in violation of the standard?  Any suggestions on how to change
the code to work on both?  The A() constructor is used fairly frequently.
As is the copy constructor.  Add a new vector constructor?

Any assistance appreciated.

Eric





-- 
Eric Korpela                        |  An object at rest can never be
korpela@ssl.berkeley.edu            |  stopped.
<a href="http://setiathome.ssl.berkeley.edu/~korpela">Click for home page.</a>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



