[H-GEN] g++/egcs peculiarity

Andrae Muys a.muys at mailbox.uq.edu.au
Thu May 14 07:01:17 EDT 1998


On Thu, 14 May 1998, Craig Eldershaw wrote:

> Hi All,
>  
> OK, here's a short C++ program:
>  
> =========================================
> class myclass
> {
> public:
>   myclass(int x, int y)
>   {}
>  
> };
>  
>  
> int main()
> {
>   int *first=new int(5);       // create an int
>   int *second=new int[10](5);  // create 10 ints
>  
>   myclass *one=new myclass(1,2);      // create a myclass
>   myclass *two=new myclass[10](1,2);  // create 10 myclasses
> }
> ===========================================
>  

Stroustrup, The C++ Programming Language, Section r.5.3.3, pg 499.

" No initializers can be specified for arrays.  Arrays of objects of a
class with constructors can be created by operator new only if the class
has a default constructor(r.12.1).  In that case, the default constructor
will be called for each element of the array."

i.e. what you did with the int there wasn't correct C++ at the time the
book was written.  Granted this reference was current May 1991 so there's
plenty of time for it to change.  Still I'd be checking that what you're
trying to do is legal.

Andrae

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Andrae Muys              "I have no wish to recite ... stratagems, for they
andrae at humbug.org.au     have all the same end in view, which is, to oblige
My stuff, Linux stuff        the enemy to make unnecessary marches in favor 
http://www.uq.edu.au/~cmamuys/   of our own designs." - Fredrick the Great.


----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe



More information about the General mailing list