【发布时间】:2015-08-21 21:57:36
【问题描述】:
这段代码不会编译:
#ifndef RemoteControl_h
#define RemoteControl_h
#include "Arduino.h"
class RemoteControl
{
public:
RemoteControl();
~RemoteControl();
static void prev_track();
static void next_track();
static void play_pause_track();
static void mute();
static void vol_up();
static void vol_down();
void respond(int code);
void add_code(int code, void (*func)());
private:
boolean active = true;
struct pair {
int _code;
void (*_func)();
};
const int max = 1000;
int database_length = 0;
pair database[max]; //This line doesn't compile unless I use a literal constant instead of "max"
};
#endif
但是如果我将下面的部分放在类的构造函数中,它就可以正常工作。
const int max = 1000;
int database_length = 0;
pair database[max];
我是否不允许在 C++ 中的类中声明数组并使用虚拟常量作为长度?如果这有所作为,我正在使用 arduino,但我希望我不了解 c++ 语言的某些内容,因为这是一个标准的 .h 文件。哦,问题不在于 .cpp 文件,因为我完全删除了它,结果相同:编译时使用文字常量长度而不是虚拟常量长度。
【问题讨论】: