定义一个静态常量变量,我在我的ADC
类由私人定义一个变量adc_cmd[9]
为static const unsigned char
。既然是恒定的,我想我会只定义它的类它的自我里面,但没有明显的工作:试图在一个类
#pragma once
class ADC{
private:
static const unsigned char adc_cmd[9] = { 0x87, 0xC7, 0x97, 0xD7, 0xA7, 0xE7, 0xB7, 0xF7, 0x00 };
//...
};
错误:
error: a brace-enclosed initializer is not allowed here before '{' token
error: invalid in-class initialization of static data member of non-integral type 'const unsigned char [9]'
...
所以我试着把这条线带出来:static const unsigned char ADC::adc_cmd[9] = { 0x87, 0xC7, 0x97, 0xD7, 0xA7, 0xE7, 0xB7, 0xF7, 0x00 };
,但是产生这个错误:
error: 'static' may not be used when defining (as opposed to declaring) a static data member
error: 'const unsigned char ADC::adc_cmd [9]' is not a static member of 'class ADC'
我显然没有正确地宣布这一点。什么是正确的方式来宣布这一点?