visual studio 2017 - C++ build errors with wxWidgets 3.1.2 and Connect method - Stack Overflow
I'm using Visual studio 2017 on a x86 machine, app is for 32bit.
wxWidgets version 3.1.2;
I have duplicated a project under another folder to serve as base of a new one, and, once removed all that is not useful, I have got some errors on exactly the same portion of code in the new project, while there were no error in the original.
t_mainform->Connect(C_SERVER_ID_APP, wxEVT_SOCKET, (wxObjectEventFunction)&TcpIP::OnServerGPRSEvent, (wxObject*)NULL, (wxEvtHandler*)this);
...
// event function
void TcpIP::OnServerGPRSEvent(wxSocketEvent& event)
{
...
}
Errors reported :
Error C2440 'type cast': cannot convert from 'void (__thiscall TcpIP::* )(wxSocketEvent &)' to 'wxObjectEventFunction'
Error C2664 'void wxEvtHandler::Connect(wxEventType,wxObjectEventFunction,wxObject *,wxEvtHandler *)': cannot convert argument 3 of 'wxObject *' to 'wxEventType'*
I have set the project properties to identical values as the original, tried many different forms of arguments list, but nothing works. I'v also tried the Bind method, but it is the same.
I tried the bind method with changing the event type to (wxCommandEvent with wxEVT_MENU event type, this can work but I still want to use the wxSocketEvent.
what is disappointing is that just compiling the other project there is no error for the same code.
Where should I look at to fix this ?
is there a global option in visual studio regarding casts ?
I'm using Visual studio 2017 on a x86 machine, app is for 32bit.
wxWidgets version 3.1.2;
I have duplicated a project under another folder to serve as base of a new one, and, once removed all that is not useful, I have got some errors on exactly the same portion of code in the new project, while there were no error in the original.
t_mainform->Connect(C_SERVER_ID_APP, wxEVT_SOCKET, (wxObjectEventFunction)&TcpIP::OnServerGPRSEvent, (wxObject*)NULL, (wxEvtHandler*)this);
...
// event function
void TcpIP::OnServerGPRSEvent(wxSocketEvent& event)
{
...
}
Errors reported :
Error C2440 'type cast': cannot convert from 'void (__thiscall TcpIP::* )(wxSocketEvent &)' to 'wxObjectEventFunction'
Error C2664 'void wxEvtHandler::Connect(wxEventType,wxObjectEventFunction,wxObject *,wxEvtHandler *)': cannot convert argument 3 of 'wxObject *' to 'wxEventType'*
I have set the project properties to identical values as the original, tried many different forms of arguments list, but nothing works. I'v also tried the Bind method, but it is the same.
I tried the bind method with changing the event type to (wxCommandEvent with wxEVT_MENU event type, this can work but I still want to use the wxSocketEvent.
what is disappointing is that just compiling the other project there is no error for the same code.
Where should I look at to fix this ?
is there a global option in visual studio regarding casts ?
Share Improve this question asked 12 hours ago JLB85JLB85 214 bronze badges1 Answer
Reset to default 0There is at least one problem in your code, you must use wxSocketEventHandler
instead of wxObjectEventFunction
.
I also strongly recommend to use Bind()
instead of Connect()
which is only provided for backwards compatibility, there is no advantage in using the latter rather than the former and there are quite a few in using Bind()
: notably, you don't need to use any casts at all.
Finally, you should also use the latest stable 3.2 instead of 5 year old 3.1.3.
- 打击终端恶意软件:刷机市场是漏网之鱼?
- 80后回忆录 那些年我们折腾过的IT玩意
- typescript - Npm 404 Not found - Stack Overflow
- docker - how to fix "communications link failure the last packet sent successfully to the server was 0 milliseconds ago
- responsive design - How achieve given UI using custom clipper in flutter - Stack Overflow
- android - Slow screen value detection using root access and uiautomator in Kotlin – Optimization help needed - Stack Overflow
- node.js - Test backend functionality nodespostman error - Stack Overflow
- batch file - Command segment in .omp.json Oh-my-posh theme - Stack Overflow
- javascript - Alpine.js menu toggle issue - Stack Overflow
- kotlin - Do I need Serialization to Transfer a MutableMap Between Minecraft Server and Client? If so, How Should I Serialize It?
- sql - Merge tables with different timestamps? - Stack Overflow
- python - Wrap_lon of the regionmask does not work with data span from -180 to 180 - Stack Overflow
- vim - Neovim - How to select autocomplete option in :e command without opening it? - Stack Overflow
- flutter - How to adjust code formatting when formatting the document - Stack Overflow
- Deploying Angular App on Azure SWA with SCSS Issues - Stack Overflow
- javascript - mapBox autofill sessionToken usage? - Stack Overflow
- eclipse - Floodlight debug Exception in thread "main" java.lang.Error - Stack Overflow