error C2511 : overloaded member function not found in 'Class'

本文探讨了C2511错误的原因及解决方法,主要聚焦于成员函数定义与声明不一致的问题,并强调了const修饰符的重要性。
17:24:40 **** Build of configuration gcc-debug for project nesting **** make MODE=debug -j16 all cd src && /usr/bin/make make[1]: Entering directory '/c/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/samples/nesting-master/nesting-master/src' MSGC: nesting/common/FlowMetaTag.msg MSGC: nesting/ieee8021q/queue/framePreemption/ExpressFrameTag.msg MSGC: nesting/linklayer/common/VLANTagDeprecated.msg MSGC: nesting/linklayer/framePreemption/PreemptedFrame.msg MSGC: nesting/linklayer/vlan/EnhancedVlanTag.msg nesting/application/ethernet/VlanEtherTrafGenSched.cc nesting/application/inet/VlanRequester.cc nesting/application/udpapp/DatagramScheduleManager.cc nesting/application/ethernet/VlanEtherTrafGen.cc nesting/application/udpapp/SendDatagramEvent.cc nesting/application/udpapp/UdpReactiveApp.cc nesting/application/udpapp/UdpScheduledTrafficGenerator.cc nesting/common/ResultFilters.cc nesting/common/schedule/CycleTimerState.cc nesting/common/schedule/GateScheduleManager.cc nesting/common/schedule/HostScheduleBuilder.cc nesting/common/schedule/ListExecuteState.cc nesting/common/schedule/ListConfigState.cc nesting/common/schedule/ScheduleFactory.cc nesting/common/time/IdealOscillator.cc nesting/common/time/LegacyClock.cc nesting/common/time/OscillatorBase.cc nesting/common/time/RealtimeClock.cc nesting/ieee8021q/queue/QueuingFrames.cc In file included from nesting/application/udpapp/DatagramScheduleManager.cc:16: In file included from .\nesting/application/udpapp/DatagramScheduleManager.h:21: .\nesting/common/schedule/ScheduleManager.h:162:27: warning: unused variable 'idleTime' [-Wunused-variable] simtime_t idleTime = cycleStartTime - clock->updateAndGetLocalTime(); ^ In file included from nesting/common/ResultFilters.cc:16: .\nesting/common/ResultFilters.h:29:18: warning: 'nesting::FlowIdFilter::receiveSignal' hides overloaded virtual functions [-Woverloaded-virtual] virtual void receiveSignal(cResultFilter* prev, simtime_t_cref t, cObject* object, cObject* details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:134:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('bool' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:135:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:136:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('unsigned long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:137:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('double' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:138:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const omnetpp::SimTime &' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:139:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const char *' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override; ^ In file included from nesting/common/ResultFilters.cc:16: .\nesting/common/ResultFilters.h:39:18: warning: 'nesting::SeqNumFilter::receiveSignal' hides overloaded virtual functions [-Woverloaded-virtual] virtual void receiveSignal(cResultFilter* prev, simtime_t_cref t, cObject* object, cObject* details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:134:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('bool' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:135:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:136:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('unsigned long' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:137:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('double' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:138:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const omnetpp::SimTime &' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override; ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include\omnetpp/cresultfilter.h:139:22: note: hidden overloaded virtual function 'omnetpp::cObjectResultFilter::receiveSignal' declared here: type mismatch at 3rd parameter ('const char *' vs 'omnetpp::cObject *') virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override; ^ In file included from nesting/application/inet/VlanRequester.cc:19: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from nesting/application/udpapp/DatagramScheduleManager.cc:16: .\nesting/application/udpapp/DatagramScheduleManager.h:41:18: warning: 'nesting::DatagramScheduleManager::initialize' hides overloaded virtual function [-Woverloaded-virtual] virtual void initialize(int stage) override;1 error generated. ^ .\nesting/common/schedule/ScheduleManager.h:101:18: note: hidden overloaded virtual function 'nesting::ScheduleManager<nesting::SendDatagramEvent>::initialize' declared here: different number of parameters (0 vs 1) virtual void initialize() override ^ In file included from nesting/application/ethernet/VlanEtherTrafGen.cc:17: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[1]: *** [Makefile:153: ../out/clang-debug/src/nesting/application/inet/VlanRequester.o] Error 1 make[1]: *** Waiting for unfinished jobs.... In file included from nesting/common/schedule/GateScheduleManager.cc:16: In file included from .\nesting/common/schedule/GateScheduleManager.h:19: .\nesting/common/schedule/ScheduleManager.h:162:27: warning: unused variable 'idleTime' [-Wunused-variable] simtime_t idleTime = cycleStartTime - clock->updateAndGetLocalTime(); ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:16: In file included from .\nesting/application/udpapp/UdpScheduledTrafficGenerator.h:25: In file included from .\nesting/application/udpapp/DatagramScheduleManager.h:21: .\nesting/common/schedule/ScheduleManager.h:162:27: warning: unused variable 'idleTime' [-Wunused-variable] simtime_t idleTime = cycleStartTime - clock->updateAndGetLocalTime(); ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:16: In file included from .\nesting/application/udpapp/UdpScheduledTrafficGenerator.h:25: .\nesting/application/udpapp/DatagramScheduleManager.h:41:18: warning: 'nesting::DatagramScheduleManager::initialize' hides overloaded virtual function [-Woverloaded-virtual] virtual void initialize(int stage) override; ^ .\nesting/common/schedule/ScheduleManager.h:101:18: note: hidden overloaded virtual function 'nesting::ScheduleManager<nesting::SendDatagramEvent>::initialize' declared here: different number of parameters (0 vs 1) virtual void initialize() override ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:16: .\nesting/application/udpapp/UdpScheduledTrafficGenerator.h:51:18: warning: 'initialize' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] virtual void initialize(int stage); ^ ../../../inet/src\inet/common/lifecycle/OperationalBase.h:52:18: note: overridden virtual function is here virtual void initialize(int stage) override; ^ In file included from nesting/application/udpapp/UdpScheduledTrafficGenerator.cc:17: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. 3 warnings and 1 error generated. make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/application/ethernet/VlanEtherTrafGen.o] Error 1 In file included from nesting/application/ethernet/VlanEtherTrafGenSched.cc:16: .\nesting/application/ethernet/VlanEtherTrafGenSched.h:88:18: warning: 'nesting::VlanEtherTrafGenSched::sendDelayed' hides overloaded virtual functions [-Woverloaded-virtual] virtual void sendDelayed(cMessage *msg); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/csimplemodule.h:215:18: note: hidden overloaded virtual function 'omnetpp::cSimpleModule::sendDelayed' declared here: different number of parameters (3 vs 1) virtual void sendDelayed(cMessage *msg, simtime_t delay, int gateid); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/csimplemodule.h:222:18: note: hidden overloaded virtual function 'omnetpp::cSimpleModule::sendDelayed' declared here: different number of parameters (4 vs 1) virtual void sendDelayed(cMessage *msg, simtime_t delay, const char *gatename, int gateindex=-1); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/csimplemodule.h:228:18: note: hidden overloaded virtual function 'omnetpp::cSimpleModule::sendDelayed' declared here: different number of parameters (3 vs 1) virtual void sendDelayed(cMessage *msg, simtime_t delay, cGate *outputgate); ^ In file included from nesting/application/ethernet/VlanEtherTrafGenSched.cc:17: .\nesting/linklayer/vlan/EnhancedVlanTag_m.h:20:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/application/udpapp/UdpScheduledTrafficGenerator.o] Error 1 1 warning and 1 error generated. make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/application/ethernet/VlanEtherTrafGenSched.o] Error 1 nesting/common/schedule/GateScheduleManager.cc:58:15: warning: unused variable 'sumTimeIntervals' [-Wunused-variable] simtime_t sumTimeIntervals = schedule.getSumTimeIntervals(); ^ nesting/common/schedule/GateScheduleManager.cc:57:14: warning: unused variable 'cycleTime' [-Wunused-variable] uint64_t cycleTime = schedule.getControlListLength(); ^ 2 warnings generated. 2 warnings generated. nesting/common/time/OscillatorBase.cc:26:7: warning: field 'timeOfLastTick' will be initialized after field 'tickEventNow' [-Wreorder] , timeOfLastTick(SimTime::ZERO) ^ nesting/common/time/OscillatorBase.cc:119:18: warning: unused variable 'elapsedTicks' [-Wunused-variable] uint64_t elapsedTicks = currentTick - lastTick; ^ In file included from nesting/ieee8021q/queue/QueuingFrames.cc:16: .\nesting/ieee8021q/queue/QueuingFrames.h:23:10: fatal error: 'inet/linklayer/vlan/VlanTag_m.h' file not found #include "inet/linklayer/vlan/VlanTag_m.h" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from nesting/common/time/RealtimeClock.cc:16: .\nesting/common/time/RealtimeClock.h:74:18: warning: 'initialize' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] virtual void initialize(); ^ C:/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/include/omnetpp/ccomponent.h:238:18: note: overridden virtual function is here virtual void initialize(); ^ nesting/common/time/RealtimeClock.cc:28:7: warning: field 'nextTick' will be initialized after field 'driftRate' [-Wreorder] , nextTick(nullptr) ^ nesting/common/time/RealtimeClock.cc:29:7: warning: field 'driftRate' will be initialized after field 'lastTick' [-Wreorder] , driftRate(0.0) ^ nesting/common/time/RealtimeClock.cc:245:7: warning: field 'listener' will be initialized after field 'localTime' [-Wreorder] : listener(listener) ^ 3 warnings generated. 1 error generated. make[1]: *** [Makefile:151: ../out/clang-debug/src/nesting/ieee8021q/queue/QueuingFrames.o] Error 1 2 warnings generated. 4 warnings generated. make[1]: Leaving directory '/c/Users/17844/omnetpp-5.6.2-src-windows/omnetpp-5.6.2/samples/nesting-master/nesting-master/src' make: *** [Makefile:11: all] Error 2 "make MODE=debug -j16 all" terminated with exit code 2. Build might be incomplete.
最新发布
10-12
### 错误 `error C2511: 'CModbusMasterDlg::OnOnComm' : overloaded member function not found` 的分析与解决方法 错误 `C2511` 表示编译器在类中找不到指定的重载成员函数。在用户提供的上下文中,该错误信息表明在类 `CModbusMasterDlg` 中未找到名为 `OnOnComm` 的重载成员函数。这种错误通常出现在使用 MFC(Microsoft Foundation Classes)进行串口通信开发时,特别是在使用 `CSerialPort` 类或其衍生类时[^1]。 #### 错误原因 1. **函数声明与定义不一致** 若在类的头文件中未正确声明 `OnOnComm` 函数,但在源文件中直接定义,或者函数签名(参数类型、数量、顺序)不匹配,将导致此错误。 2. **未正确连接消息映射** 在 MFC 中,串口通信通常依赖 `ON_MESSAGE` 或 `ON_NOTIFY` 等宏进行消息绑定。如果 `OnOnComm` 函数未通过 `ON_MESSAGE(WM_COMM_NOTIFY, OnOnComm)` 正确绑定,则可能引发该错误。 3. **拼写错误或作用域问题** 函数名拼写错误、未使用类作用域解析(如 `CModbusMasterDlg::OnOnComm`)或函数定义位置错误也可能导致编译器无法识别函数。 #### 解决方法 1. **确保函数在类定义中正确声明** 在 `CModbusMasterDlg.h` 文件中确保 `OnOnComm` 函数已声明为类的成员函数,并且使用正确的参数列表。 ```cpp afx_msg LRESULT OnOnComm(WPARAM wParam, LPARAM lParam); ``` 2. **在消息映射中正确绑定函数** 在 `CModbusMasterDlg.cpp` 文件的消息映射表中添加对应的绑定宏。 ```cpp BEGIN_MESSAGE_MAP(CModbusMasterDlg, CDialogEx) // 其他消息绑定 ON_MESSAGE(WM_COMM_NOTIFY, OnOnComm) END_MESSAGE_MAP() ``` 3. **确保函数定义正确** 在 `CModbusMasterDlg.cpp` 文件中定义 `OnOnComm` 函数,并确保其参数与返回类型与声明一致。 ```cpp LRESULT CModbusMasterDlg::OnOnComm(WPARAM wParam, LPARAM lParam) { // 处理串口通信事件 return 0; } ``` 4. **检查头文件包含和类继承** 确保 `CModbusMasterDlg` 正确继承自 `CDialogEx` 或 `CDialog`,并包含必要的 MFC 头文件,如 `afxwin.h` 和 `afxext.h`。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值