Article View: net.lang.c++
Article #247Arrays of Classes
From: cohler
Date: Mon, 07 Jul 1986 20:42
Date: Mon, 07 Jul 1986 20:42
43 lines
1760 bytes
1760 bytes
Machine : c++ on vax/750 running BSD 4.2
a Bug ?
We have encountered a problem with allocating storage for
arrays of classes. Looking at the generated c code it seems
that 'new' forgets to cast '_vec_new()'. Has anyone else
had similar problems ?
The following code illustrates the problem - which
goes away by compiling with -DBUGFIX.
Also complex.h does not have a default constructor -
so arrays of complex numbers cant be defined at all - this
of course can be fixed by providing a default constructor
in complex.h.
Gene Cohler cohler@lnsvax.tn.cornell.EDU
Newman Lab, Cornell Univ jbvy@cornella.BITNET
Ithaca NY 14853-5001 {decvax,ihnp4,cmcl2,vax135}
!cornell!lnsvax!cohler
======================= source code ======================
// tst.c -> Arrays of classes ?
class test
{
public:
int i1;
int i2;
test(){i1 = 0; i2 = 0;}
};
main()
{
test *t1 ;
#ifdef BUGFIX
t1 = (struct test *) new test[10] ;
#else
t1 = new test[10] ;
#endif BUGFIX
}
Technical Details
Message-ID:
<566@batcomputer.TN.CORNELL.EDU>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!hplabs!tektronix!uw-beaver!cornell!batcomputer!cohlerShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!hplabs!tektronix!uw-beaver!cornell!batcomputer!cohler From: cohler@batcomputer.UUCP Newsgroups: net.lang.c++ Subject: Arrays of Classes Message-ID: <566@batcomputer.TN.CORNELL.EDU> Date: Mon, 7-Jul-86 16:42:55 EDT Article-I.D.: batcompu.566 Posted: Mon Jul 7 16:42:55 1986 Date-Received: Thu, 10-Jul-86 01:06:38 EDT Organization: Theory Center, Cornell U., Ithaca NY Lines: 43 Keywords: arrays, classes, complex