X
Xavier Roche
Hi folks,
How to assign an array in a constructor, when the array is needed in
another constructor ?
Typical case: a class "A" defined elsewhere (ie. not my code) which
takes an int&/char** as constructor:
class A {
public:
A(int & argc, char ** argv);
}
And my class B, which has A as member. A must be initialized in the
constructor ; therefore I tried the following construct:
class B {
public:
B();
protected:
A a;
private:
char progName[4]; // dummy
int argc;
char *argv[2];
}
B::B(): progName("foo"),
argc(1),
argv({progName, NULL}),
a(argc, argv)
{
}
This code is not correct (and won't compile) - as I can not initialize
the array directly. ("expected primary-expression before '{' token" --
"ISO C++ forbids assignment of arrays")
Is there a way out, or do I have to give up and use a pointer to A as
member, with proper "manual" new construct ?
Thanks in advance for any enlightenment.
How to assign an array in a constructor, when the array is needed in
another constructor ?
Typical case: a class "A" defined elsewhere (ie. not my code) which
takes an int&/char** as constructor:
class A {
public:
A(int & argc, char ** argv);
}
And my class B, which has A as member. A must be initialized in the
constructor ; therefore I tried the following construct:
class B {
public:
B();
protected:
A a;
private:
char progName[4]; // dummy
int argc;
char *argv[2];
}
B::B(): progName("foo"),
argc(1),
argv({progName, NULL}),
a(argc, argv)
{
}
This code is not correct (and won't compile) - as I can not initialize
the array directly. ("expected primary-expression before '{' token" --
"ISO C++ forbids assignment of arrays")
Is there a way out, or do I have to give up and use a pointer to A as
member, with proper "manual" new construct ?
Thanks in advance for any enlightenment.