James Kanze
10/31/2008 12:06:00 PM
On Oct 31, 9:42 am, Urs Thuermann <u...@janus.isnogud.escape.de>
wrote:
> I have some old code I've written several years ago that
> doesn't compile with newer versions of GCC. The code
> allocates an array of objects that need to be initialized by
> calling a constructor with one argument:
> class B;
> class A {
> B *b;
> public:
> A(B *p) : b(p) {}
> };
> class B {
> public:
> void foo() {
> // this declaration is ok
> A a(this);
> // the following causes an error with newer GCC:
> // error: ISO C++ forbids initialization in array new
> A *arr = new A[10](this);
> }
> };
> int main()
> {
> B b;
> }
> This worked with g++ until version 3.3.x, but not since 3.4.x.
> The problem is in the expression new A[10](this), since
> according to GCC, initialization in array new is forbidden.
It's always been forbidden.
> How would I initialize the array elements in ISO C++?
std::vector< A > v( 10, this ) ;
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34