首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C++中调用此Lambda函数

如何在C++中调用此Lambda函数
EN

Stack Overflow用户
提问于 2018-02-15 13:20:46
回答 1查看 760关注 0票数 0

我在这个类的保护的函数中编写了一个lambda函数。

代码语言:javascript
复制
class Tetris: protected TetrisArea<true>
{
public:
    Tetris(unsigned rx) : TetrisArea(rx), seq(),hiscore(0),hudtimer(0) {}
    virtual ~Tetris() { }

protected:
    // These variables should be local to GameLoop(),
    // but because of coroutines, they must be stored
    // in a persistent wrapper instead. Such persistent
    // wrapper is provided by the game object itself.
    Piece seq[4];

lambda函数,

代码语言:javascript
复制
auto fx = [&seq]() {  seq[0].x=4;       seq[0].y=-1;
                        seq[1].x=Width;   seq[1].y=Height-4;
                        seq[2].x=Width+4; seq[2].y=Height-4; }; 

这就是问题所在。我发现了这些错误:

代码语言:javascript
复制
 error: capture of non-variable 'Tetris::seq' 
         auto fx = [&seq]() {  seq[0].x=4;       seq[0].y=-1;
 error: 'this' was not captured for this lambda function
     auto fx = [&seq]() {  seq[0].x=4;       seq[0].y=-1;

。。同时也为以后函数中的seqn提供参考。

我试图在保护的函数中直接输入代码,但是虽然它编译了,但它似乎无法正常工作,因为该程序来自于他的俄罗斯方块Dos游戏中的Youtube频道Bisqwit。

EN

回答 1

Stack Overflow用户

发布于 2018-02-15 13:23:36

当它读取时,您尝试捕获对象的成员而不捕获对象本身。将[&seq]转换为[this],看看会发生什么。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48808297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档