我在私有下的类中将变量定义adc_cmd[9]
为 a 。由于它是一个常量,我想我会在它自己的类中定义它,但这显然不起作用:static const unsigned char
ADC
#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'
我显然没有正确地声明这一点。声明这个的正确方法是什么?