【发布时间】:2012-04-17 14:15:50
【问题描述】:
我在我的类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'
我显然没有正确声明这一点。声明这个的正确方法是什么?
【问题讨论】: