K
Klaus Rudolph
Hi all,
I have 2 classes, the second one should include an
array of the first on. The first class should not have a default
constructor. How could I use an array of the first classes?
If it is impossible to initialize the array before entering the
constructor , it
would never be possible to use arrays of classes in C++ whitout using a
default constructor.
Is that correct?
class A {
protected:
int a;
public:
A(int _a): a(_a) {}
};
class B {
protected:
A arr[2];
public:
B(int _a1, int _a2): arr(?????????????) {} //<-------------------
};
int main() {
B b(1,2);
return 0;
}
The marked line is my problem. Is there no way to initialize the array?
Is using a vector<> the only solution here?
Regards
Klaus
I have 2 classes, the second one should include an
array of the first on. The first class should not have a default
constructor. How could I use an array of the first classes?
If it is impossible to initialize the array before entering the
constructor , it
would never be possible to use arrays of classes in C++ whitout using a
default constructor.
Is that correct?
class A {
protected:
int a;
public:
A(int _a): a(_a) {}
};
class B {
protected:
A arr[2];
public:
B(int _a1, int _a2): arr(?????????????) {} //<-------------------
};
int main() {
B b(1,2);
return 0;
}
The marked line is my problem. Is there no way to initialize the array?
Is using a vector<> the only solution here?
Regards
Klaus