C++ 如何在C++;

C++ 如何在C++;,c++,lambda,C++,Lambda,我在这个类的受保护的void函数中编写了一个lambda函数 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

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

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];
这就是问题所在。我犯了以下错误:

 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;
。。也可用于后续函数中的seq[n]参考


我试图直接在protected void函数中键入代码,但尽管它可以编译,但似乎无法正常工作,因为该程序来自Youtube频道Bisqwit在他的俄罗斯方块Dos游戏中提供的内容。

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

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

谢谢,它仍然有效!非常感谢!如果您可以使用C++14,那么有一种使用初始化的lambda捕获表达式的新方法:
auto-fx=[&ref=seq]({ref[0].x=4;等)}
实际上,它可以说
[&seq=seq]
,然后按照原始版本继续。这样一个简单的名称重用被应用到了链接问题中。无论如何,感谢它起作用了!非常感谢!如果您可以使用C++14,那么有一种使用初始化的lambda捕获表达式的新方法:
auto-fx=[&ref=seq]({ref[0].x=4;等)}
实际上,它可以说
[&seq=seq]
,然后按照原始版本继续。这样一个简单的名称重用被应用到链接的问题中。一个重复的问题,我不喜欢搜索相关的问题!然而,希望在不久的将来对其他人有用,你也应该发布一篇文章。该代码中没有受保护的方法。我猜你漏掉了一个重复的部分,真的,我不好没有搜索相关的问题!然而,希望在不久的将来对其他人有用,你也应该发布一篇文章。该代码中没有受保护的方法。我猜你漏掉了那部分
 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;