I have the following class and struct (stripped down for simplicity)
a.h
class A {
B *myArray;
}
a.cc
A::A() {
myArray = new B[1];
}
b.h
struct B {
int number;
}
b.cc
B::B(int n): number(n) {
}
As you can see the class B
only has the constructor that takes an integer, so when I do myArray = new B[1]
it throws no matching constructor for initialization of 'B[1]'
.
How can I fix this? I've tried doing an array of pointers instead of an array of type B
but it doesn't work because of the way information is entered into the program.
I cannot add a new constructor to B
. I can only add private variables and methods. I can only use the following libraries: iostream, fstream, sstream, iomanip, string, and utility.