U
Urs Thuermann
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.
How would I initialize the array elements in ISO C++?
urs
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.
How would I initialize the array elements in ISO C++?
urs