I want to have a big container (specifically a std::array) the size of which I know at compile time but which I can specify from the constructor.
I have been able to do the first part: i.e. a std::array which a size specified at compile time. Schematically:
// hpp
constexpr int my_size = 100;
class C
{
std::array<int, my_size> data;
}
// main
c = C()
Now I would like to do the same thing, but with the std::array passed into the class constructor, possibly as an constexpr:
// hpp
class C
{
std::array<int, mysize> data;
C(constexpr int mysize);
}
// cpp
C::C(constexpr int mysize)
{
data = std::array<int, mysize>
}
// main
constexpr int mysize = 100;
c = C(mysize);
Obviously this is wrong because mysize is passed in the constructor, but mysize is also part of the type which has to be known at the point of declaration.
So how do I do this?
C. Therefore,sizeof(C)must be the same and cannot depend on a constructor parameter.