I am a newbie in C++ and I have encountered a problem that I need to define a new data types (unions concretely) via typedef in my class. The relevant code snippet of .h module of my class is following
class Manager
{
public:
static const uint8_t NO_BYTES_IN_PACKET;
static const uint8_t NO_PYLD_BYTES_IN_CONTROL_PACKET;
// control packet structure
typedef union{
struct{
uint8_t header[3];
uint8_t payload[NO_PYLD_BYTES_IN_CONTROL_PACKET];
}pkt_parts_t;
uint8_t pkt_array[NO_BYTES_IN_PACKET];
}control_pkt_u;
private:
}
My problem is that the constants
static const uint8_t NO_BYTES_IN_PACKET;
static const uint8_t NO_PYLD_BYTES_IN_CONTROL_PACKET;
are defined in associated .cpp module
const uint8_t Manager::NO_BYTES_IN_PACKET = 8;
const uint8_t Manager::NO_PYLD_BYTES_IN_CONTROL_PACKET = 5;
Due to that I have been receiving an error message: error: array bound is not an integer constant before ']' token during compilation process. My idea was to move the union definition into the .cpp module but I am not sure whether it is correct approach. What are your opinions? Thank you for any ideas.