Well, the question is not as silly as it sound.
I am using C++11 <array>
and want to declare an array like this:
array<int, MAX_ARR_SIZE> myArr;
The MAX_ARR_SIZE
is to be defined in a header file and could be very large i.e. 10^13. Currently I am typing it like a pre-school kid
#define MAX_ARR_SIZE 1000000000000000
I can live with it if there is no alternative. I can't use pow(10, 13)
here since it can not be evaluated at compile time; array initialization will fail. I am not aware of any shorthand to type this.
Using #define for constants is more a way of C than C++.
You can define your constant in this way:
const size_t MAX_ARR_SIZE(1e15);
In this case, using a const size_t
instead of #define
is preferred.
I'd like to add that, since C++14, when writing integer literals, you could add the optional single quotes as separator.
1'000'000'000'000'000
This looks more clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With