I need to pass a pointer to an array in a constructor (I am aware that using plain arrays in C++ is considered by many as bad practice, but for now I just want to go ahead with it).
Please consider the following code:
// let's omit includes
class A {
// irrelevant
}
class B {
public:
//irrelevant
void someMethod() {
_c = new C(array_id);
}
private:
C* _c;
A* array_id[SOME_CONST];
}
class C {
public:
C(A* a_array) : _array(a_array) {}
private:
A* _array;
}
Trying to compile will result in a:
error: no matching function for call to C::C(A* [SOME_CONST])'
As far as I know, the identifier of an array decays to a pointer to the first element of the array, but it seems that it cannot be used directly. How can I effectively pass a pointer to an array of A* in the constructor of C?
A*, so a pointer to that is anA**, and you don't have a constructor that accepts anA**.A* array_id[SOME_CONST];beA array_id[SOME_CONST];?