Lambda error in code when making form and onload

2019-09-15 03:16发布

I get this error:

IntelliSense: no suitable conversion function from "lambda []void (Form::Form *arg1)->void" to "Form::OnLoad" exists c:\users\topkek\desktop\project\test\tset\test\main.cpp

Real error:

Error 8 error C2440: 'type cast' : cannot convert from '`anonymous-namespace'::' to 'Form::OnLoad' c:\users\topkek\desktop\project\test\tset\tes‌​t\main.cpp

This is the code:

new Form::Form("TEST_MAIN", "Test main", (Form::OnLoad)[](Form::Form* arg1)->void {

form.h:

typedef void(*OnLoad)(Form*);
Form(const char* WindowClass, const char* Title, OnLoad Func = NULL);

Form.cpp:

Form::Form(const char* szWindowClass, const char* Title, OnLoad Func) {

1条回答
狗以群分
2楼-- · 2019-09-15 03:28
(Form::OnLoad)[](Form::Form* arg1)->void { /*...*/ })

That is one weird lambda :)

I'm not sure what exactly you are trying to do, but you don't need a lambda for this:

auto f = new Form::Form("TEST_MAIN", "Test main", &Form::OnLoad);
                                                  ^^^^^^^^^^^^^
                                                  Address of function

If you want a lambda, drop the start:

auto f = new Form::Form("TEST_MAIN", "Test main", [](Form::Form* arg1)->void {});
查看更多
登录 后发表回答