vs中 error C2146: 语法错误 : 缺少“;”(在标识符“m_btn1”的前面)

本文介绍了一个基于对话框的MFC项目btnRun遇到的编译错误及其解决方案。错误涉及成员变量声明问题,通过正确引入包含成员变量声明的头文件得以解决。

项目名为btnRun,基于对话框的MFC 中新建一个类CNewButton,并定义了两个成员变量m_btn1,m_btn2;

编译时错误:

1>e:\vsproject\btnRunDlg.h(91) : error C2146: 语法错误 : 缺少“;”(在标识符“m_btn1”的前面)

 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int


解决:

在头文件btnRunDlg.h中添加#include“NewButton.h” 即可。

#include "mysystem.h" #include "ebtn.h" int my_system_init() { // ... 其他硬件和外设初始化 (GPIO, 时钟, 定时器等) ... // 初始化 ebtn 库 int init_ok = ebtn_init( static_buttons, // 静态按键数组的指针 EBTN_ARRAY_SIZE(static_buttons), // 静态按键数量 (用宏计算) static_combos, // 静态组合按键数组的指针 (如果没有,传 NULL, 0) EBTN_ARRAY_SIZE(static_combos), // 静态组合按键数量 (如果没有,传 0) my_get_key_state, // 你的状态获取回调函数 my_handle_key_event // 你的事件处理回调函数 ); if (!init_ok) { // 初始化失败,可能是参数错误 printf("Error: ebtn_init failed!\n"); return -1; // 或者进行其他错误处理 } // --- 配置组合键 (如果使用了组合键) --- // 1. 找到参与组合的普通按键的内部索引 (Index) // 注意:这个内部索引不一定等于你设置的 key_id! int key1_index = ebtn_get_btn_index_by_key_id(1); // 获取 KEY1 (ID=1) 的内部索引 int key2_index = ebtn_get_btn_index_by_key_id(2); // 获取 KEY2 (ID=2) 的内部索引 // 2. 将这些索引对应的按键添加到组合键定义中 // 确保索引有效 (>= 0) if (key1_index >= 0 && key2_index >= 0) { // 假设 static_combos[0] 是我们定义的 ID=101 的组合键 ebtn_combo_btn_add_btn_by_idx(&static_combos[0], key1_index); // 将 KEY1 添加到组合键 ebtn_combo_btn_add_btn_by_idx(&static_combos[0], key2_index); // 将 KEY2 添加到组合键 } else { printf("Warning: Could not find index for combo button setup.\n"); // 可能需要检查 key_id 是否正确,或者 ebtn_init 是否成功 } // ... 其他初始化代码 ... return 0; // 初始化成功 } 为社么报错Build started: Project: GD32_DEMO_01 *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keli 5\code\ARM\ARMCC5\Bin' Build target 'GD32_DEMO_01' compiling mysystem.c... ..\APP\mysystem.h(6): warning: #1295-D: Deprecated declaration my_system_init - give arg types int my_system_init(); ..\APP\mysystem.c(9): error: #20: identifier "static_buttons" is undefined static_buttons, // 静态按键数组的指针 ..\APP\mysystem.c(11): error: #20: identifier "static_combos" is undefined static_combos, // 静态组合按键数组的指针 (如果没有,传 NULL, 0) ..\APP\mysystem.c(13): error: #20: identifier "my_get_key_state" is undefined my_get_key_state, // 你的状态获取回调函数 ..\APP\mysystem.c(14): error: #20: identifier "my_handle_key_event" is undefined my_handle_key_event // 你的事件处理回调函数 ..\APP\mysystem.c(19): warning: #223-D: function "printf" declared implicitly printf("Error: ebtn_init failed!\n"); ..\APP\mysystem.c(36): warning: #223-D: function "printf" declared implicitly printf("Warning: Could not find index for combo button setup.\n"); ..\APP\mysystem.c: 3 warnings, 4 errors "GD32_DEMO_01\GD32_DEMO_01.axf" - 4 Error(s), 3 Warning(s). Target not created. Build Time Elapsed: 00:00:02
05-13
CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:208:5: warning: implicit declaration of function ‘lv_textarea_set_editable’; did you mean ‘lv_textarea_get_label’? [-Wimplicit-function-declaration] 208 | lv_textarea_set_editable(lyric_area, false); | ^~~~~~~~~~~~~~~~~~~~~~~~ | lv_textarea_get_label /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c: In function ‘cd_click_event_cb’: /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:271:13: warning: implicit declaration of function ‘lv_obj_get_hidden’; did you mean ‘lv_obj_get_index’? [-Wimplicit-function-declaration] 271 | if (lv_obj_get_hidden(lyric_area)) { | ^~~~~~~~~~~~~~~~~ | lv_obj_get_index /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c: At top level: /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:284:1: warning: data definition has no type or storage class 284 | lv_init(); | ^~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:284:1: warning: type defaults to ‘int’ in declaration of ‘lv_init’ [-Wimplicit-int] /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:284:1: error: conflicting types for ‘lv_init’; have ‘int()’ In file included from /mnt/hgfs/CODE/20-lvgl-sdl/./lvgl/lvgl.h:35, from /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/../ui.h:13, from /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:6: /mnt/hgfs/CODE/20-lvgl-sdl/./lvgl/src/core/lv_obj.h:202:6: note: previous declaration of ‘lv_init’ with type ‘void(void)’ 202 | void lv_init(void); | ^~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:288:5: warning: data definition has no type or storage class 288 | setup_ui(); | ^~~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:288:5: warning: type defaults to ‘int’ in declaration of ‘setup_ui’ [-Wimplicit-int] /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:288:5: error: conflicting types for ‘setup_ui’; have ‘int()’ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:161:6: note: previous definition of ‘setup_ui’ with type ‘void()161 | void setup_ui() { | ^~~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:289:5: warning: data definition has no type or storage class 289 | setup_btn_events(); | ^~~~~~~~~~~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:289:5: warning: type defaults to ‘int’ in declaration of ‘setup_btn_events’ [-Wimplicit-int] /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:289:5: error: conflicting types for ‘setup_btn_events’; have ‘int()’ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:247:6: note: previous definition of ‘setup_btn_events’ with type ‘void()’ 247 | void setup_btn_events() { | ^~~~~~~~~~~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:292:17: error: expected declaration specifiers or ‘...’ before string constant 292 | load_lyrics("music/current_song.lrc"); | ^~~~~~~~~~~~~~~~~~~~~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:294:5: error: expected identifier or ‘(’ before ‘while’ 294 | while(1) { | ^~~~~ /mnt/hgfs/CODE/20-lvgl-sdl/ui_a/screens/ui_Screen6.c:299:5: error: expected identifier or ‘(’ before ‘return’ 299 | return 0; | ^~~~~~ make[2]: *** [ui_a/CMakeFiles/ui.dir/build.make:146:ui_a/CMakeFiles/ui.dir/screens/ui_Screen6.c.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:274:ui_a/CMakeFiles/ui.dir/all] 错误 2 make: *** [Makefile:136:all] 错误 2 gec@gec-u:/mnt/hgfs/CODE/20-lvgl-sdl/build$ 出现了这些代码该怎么解决
09-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值