Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ID_按钮未使用常量表达式初始化_C++_Wxwidgets - Fatal编程技术网

C++ ID_按钮未使用常量表达式初始化

C++ ID_按钮未使用常量表达式初始化,c++,wxwidgets,C++,Wxwidgets,我想在我的应用程序中使用“回车”和“Shift”键。为了实现这一点,我找到了一些代码 当我尝试使用此代码段时,会出现以下错误: D:\WindowsDgps\WindowsDgpsGUI\PortsDialog.cpp | 171 |错误:“PortsDialog::ID_BUTTON1”的值在常量表达式中不可用| 及 D:\WindowsDgps\WindowsDgpsGUI\PortsDialog.cpp | 35 |注意:“PortsDialog::ID_BUTTON1”未使用常量表达式初

我想在我的应用程序中使用“回车”和“Shift”键。为了实现这一点,我找到了一些代码

当我尝试使用此代码段时,会出现以下错误:

D:\WindowsDgps\WindowsDgpsGUI\PortsDialog.cpp | 171 |错误:“PortsDialog::ID_BUTTON1”的值在常量表达式中不可用|

D:\WindowsDgps\WindowsDgpsGUI\PortsDialog.cpp | 35 |注意:“PortsDialog::ID_BUTTON1”未使用常量表达式初始化|

我做错了什么?我必须如何声明ID才能工作?我使用了wxWidgets自身生成的标准实现

const long PortsDialog::ID_STATICTEXT1 = wxNewId();
const long PortsDialog::ID_TEXTCTRL1 = wxNewId();
const long PortsDialog::ID_BUTTON1 = wxNewId();
const long PortsDialog::ID_TEXTCTRL2 = wxNewId();
const long PortsDialog::ID_BUTTON2 = wxNewId();
const long PortsDialog::ID_BUTTON3 = wxNewId();
const long PortsDialog::ID_PANEL1 = wxNewId();

我可以做些什么,以便在静态文本字段中使用Enter键激活按钮?

PortsDialog::ID_BUTTON1
是常量,您无法更改它,它不是编译时常量。它的值在编译时不是固定的,而是在运行时初始化的

开关中的大小写必须是编译时常量


您不能在此处使用
开关,但必须使用
if
else if
链。

虽然
端口Dialog::ID_BUTTON1
是常量,您无法更改它,但它不是编译时常量。它的值在编译时不是固定的,而是在运行时初始化的

开关中的大小写必须是编译时常量

这里不能使用
开关
,但必须使用
if
else if

const long PortsDialog::ID_STATICTEXT1 = wxNewId();
const long PortsDialog::ID_TEXTCTRL1 = wxNewId();
const long PortsDialog::ID_BUTTON1 = wxNewId();
const long PortsDialog::ID_TEXTCTRL2 = wxNewId();
const long PortsDialog::ID_BUTTON2 = wxNewId();
const long PortsDialog::ID_BUTTON3 = wxNewId();
const long PortsDialog::ID_PANEL1 = wxNewId();