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.
- 台式电脑“玩”安卓(图)
- 鲍尔默:未来5至10年微软将不再像一家软件公司
- python - How to solve this TensorflowTensorboard compatibility problem? - Stack Overflow
- c - Does GLib rely on undefined behavior with how it utilizes casting between GArray and GRealArray? - Stack Overflow
- node.js - Mongoose schema worked with the main db but not with test db - Stack Overflow
- sqlite - invalid call to function 'connect' in base 'NAtiveScript'. expected 3 arguments in godo
- node.js - Cors errors S3 Upload node - Stack Overflow
- linux - Unable to access devttyS0 as a regular user, despite having the right permissions - Stack Overflow
- azure managed identity - Durable Function error "This request is not authorized to perform this operation" - S
- typescript - How to keep autosuggestion with generics when working with keyof? - Stack Overflow
- django - SimpleJWT: Re-apply Blacklist Token Migration: "Table 'token_blacklist_blacklistedtoken' doesn
- netlogo - Indirect allocation of resources than intended - Stack Overflow
- python - Steps approximation for time series scatter with mean changing every K number of steps using BIC - Stack Overflow
- kotlin - How to implement "Swipe to Go Back" in iOS with Compose Multiplatform (1.7.3) - Stack Overflow
- c - I'm getting segmentation error: core dumped when loading a list of string, especially for long lists. There is a mem
- php - 406 error when sendingreceiving JSON data - Stack Overflow
- GHC unable to find mingwinclude directory on Windows - Stack Overflow