I have a code a following (simplified version):
#define MESSAGE_SIZE_MAX 1024
#defined MESSAGE_COUNT_MAX 20
class MyClass {
public:
.. some stuff
private:
unsigned char m_messageStorage[MESSAGE_COUNT_MAX*MESSAGE_SIZE_MAX];
};
I don't like defines, which are visible to all users of MyCalss.
How can I do it in C++ style?
Thanks Dima
Why don't you simply use a constant?
const int message_size_max = 1024;
Note that unlike C, C++ makes constant variables in global scope have static linkage by default.
The constant variable above is a constant expression and as such can be used to specify array sizes.
char message[message_size_max];
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