在 QT 项目开发过程中,你可能会遇到以下错误:/n/nd://QTProjects//JBMN//mainwindow.cpp:117: error: invalid use of non-static data member 'MainWindow::lpPrevWndFunc'/n../JBMN//mainwindow.cpp: In function 'LRESULT func_Message(HWND, UINT, WPARAM, LPARAM)':/n../JBMN//mainwindow.cpp:117:41: error: invalid use of non-static data member 'MainWindow::lpPrevWndFunc'/n 117 | return CallWindowProcA (MainWindow::lpPrevWndFunc, hwnd, uMsg, wParam, lParam);/n | ^~~~~~~~~~~~~/n/n这个错误提示是因为在函数 func_Message 中尝试访问非静态数据成员 MainWindow::lpPrevWndFunc,但是该函数是静态函数,无法访问非静态数据成员。/n/n要解决这个问题,可以将函数 func_Message 设为成员函数,并在调用该函数时使用对象名来访问非静态数据成员 lpPrevWndFunc。修改后的代码示例如下:/n/ncpp/nLRESULT MainWindow::func_Message(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)/n{/n return CallWindowProcA(lpPrevWndFunc, hwnd, uMsg, wParam, lParam);/n}/n/n/n注意,修改成员函数后,需要将函数声明和定义中的 static 关键字去掉,否则会出现语法错误。/n

QT 错误:'invalid use of non-static data member' 解决方法

原文地址: https://www.cveoy.top/t/topic/nr6Q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录