I have a class template which accepts another class template and an int
as the template parameters. I would like to create one, shared two-dimensional array which will be accessible to all class instances as well as static public
methods (so that its not bound to any specific instance, but the class
). I would like the array to be initialised at compile time. I cannot really nail it down; I have been trying various options but always end up with an error...
Example:
template <const unsigned int x, const unsigned int dim>
class Class1<Class2<x>, dim> {
private:
static constexpr int multable[dim][dim] = initializeMultable();
public:
static constexpr const int(*initializeMultable())[dim] {
static int result[dim][dim];
for (unsigned int i = 0; i < dim; ++i) {
for (unsigned int j = 0; j < dim; ++j) {
result[i][j] = i + j // whatever
}
}
return result;
}
What is the proper way to initialise such an array at compile time?