0
我是新的使用c + + 11功能,也尝试使用SDL_Widget-2 lib为我的项目建立一个简单的桂。但我被陷在问题:C++ 11 Lambda函数编译错误
#include "sdl-widgets.h"
class Builder
{
public:
Builder():top_win(nullptr)
,but(nullptr)
{
top_win=new TopWin("Hello",Rect(100,100,120,100),0,0,false,
[]() {
top_win->clear();
draw_title_ttf->draw_string(top_win->render,"Hello world!",Point(20,40));
}
);
but=new Button(top_win,0,Rect(5,10,60,0),"catch me",
[](Button *b) {
static int dy=60;
b->hide();
b->move(0,dy);
b->hidden=false;
dy= dy==60 ? -60 : 60;
});
}
private:
TopWin * top_win;
Button *but;
};
int main(int,char**) {
Builder aViewBuilder;
get_events();
return 0;
}
在编译阶段的错误:
在拉姆达功能:打印
error: 'this' was not captured for this lambda function
error: 'this' was not captured for this lambda function
此错误两次INT控制台。 我有尝试:
[this](){}
[=](){}
和
[&](){}
用不同的编译错误,但不能走得更加进一步。 任何可以看到修复?
什么是'draw_title_ttf'?它从何而来?它没有在课堂上声明。 – Gasim
是sdl-widgets lib的一个函数,它是sdl2 lib的一个包装 –