Topic: Standard on dynamic memory allocation of arrays
Author: Edward Diener <eddielee@abraxis.com>
Date: 1998/09/12 Raw View
In neither case can you initialize the elements of your array using the 'new'
syntax.
Devaki Parikh wrote:
> Hi! All,
> Could someone please tell me about the c++ standard for dynamically
> allocating arrays ? Are the following statements valid ?
>
> int **p1, *p2;
>
> p1 = new (int*) [10] (0);
> // would the above line of code generate array of ten pointers to
> integers and initialize // them to NULL ?
>
> p2 = new int [10] (5);
> // would the above line of code generate an array of ten integers all
> initialized to 5 ?
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1998/09/12 Raw View
Devaki Parikh wrote:
> Could someone please tell me about the c++ standard for dynamically
> allocating arrays ? Are the following statements valid ?
> int **p1, *p2;
> p1 = new (int*) [10] (0);
> // would the above line of code generate array of ten pointers to
> integers and initialize // them to NULL ?
> p2 = new int [10] (5);
> // would the above line of code generate an array of ten integers all
> initialized to 5 ?
Nope. operator new[] can only use a default constructor for the objects
in the array, and the default constructor for built-in types is empty,
meaning that the values are undefined. You're not the first person to
wish it were otherwise.
--
Ciao,
Paul
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Devaki Parikh <Devaki_N_Parikh@res.raytheon.com>
Date: 1998/09/10 Raw View
Hi! All,
Could someone please tell me about the c++ standard for dynamically
allocating arrays ? Are the following statements valid ?
int **p1, *p2;
p1 = new (int*) [10] (0);
// would the above line of code generate array of ten pointers to
integers and initialize // them to NULL ?
p2 = new int [10] (5);
// would the above line of code generate an array of ten integers all
initialized to 5 ?
Thanks
Devaki
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]