I have two classes A and B in C++11. There's a static array in class A, which is used in class B. Here is the simplified problem:
// A.h
class A {
public:
static int const a[4];
};
// A.cpp
int const A::a[4] = {1,2,3,4};
// B.h
class B {
public:
void method();
};
// B.cpp
void B::method() {
for(auto const& it:a) {
/* do something */
}
}
It works, but it requires the explicit definition of the array size. I would like to change the content of the array initializer from time to time, at compile time, without the manual redefinition of its size.
What would be an equivalent, but more efficient way to do this?
std::vector?std::array::sizeis marked asconstexpr, I don't see any issues with that.std::arraythey are forced to do so. Only with aC-stylearray can the size be omitted.