Problems with dynamic arrays initialization
Olivier Galibert
Olivier.Galibert@mines.u-nancy.fr
Thu Nov 27 16:12:00 GMT 1997
cd2 isn't completely clear about whether new Class[42](666);
is a vlid syntax to allocate an array and initialize it
with a non-default constructor. It looks like it is valid
though. egcs (971122) has two problems with that:
1- Abuse of the copy constructor:
-O<-----------
class C {
public:
void f();
};
class A {
public:
A();
private:
A(const A&);
};
class B : public A {
public:
B(C *);
};
void C::f()
{
new B[10](this);
}
-O<-----------
This gives:
weird.cc: In method `B::B(const class B &)':
weird.cc:11: `A::A(const class A &)' is private
weird.cc:21: within this context
But there is _no_ reason at all to call the copy constructor.
Second problem:
-O<-----------
class A {
public:
A(int, int);
};
int main()
{
new A[10](42, 666);
return 0;
}
-O<-----------
parse.cc: In function `int main()':
parse.cc:8: no matching function for call to `A::A (int)'
parse.cc:4: candidates are: A::A(const A &)
parse.cc:3: A::A(int, int)
Looks like the initializer is taken as a comma expression
instead of a parameter list.
For the curious, both of these problems where detected
while compiling kde. Regression from 2.7.2 ? (I don't have
it anymore)
OG.
PS: I'm on egcs@ but not on egcs-bugs@
More information about the Gcc-bugs
mailing list