Answer the question
In order to leave comments, you need to log in
Why does the compiler swear at an array whose dimension is given by a static constant?
Hello, I declare the following structure:
struct Packet
{
static const int bytes_for_content; //определяется в соотв-ем cpp файле
//...
char content[bytes_for_content]; //это компилятору и не понравилось
};
Answer the question
In order to leave comments, you need to log in
The size of the fields of the structure is determined at compile time, and the value of the constant is assigned at runtime of the program, so it swears. Use #define for things like this.
struct Packet
{
static const int bytes_for_content;
//...
char content[bytes_for_content]; //это компилятору и не понравилось
};
const int Packet::bytes_for_content = 100;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question