gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:37:08 26 4
gpt4 key购买 nike

<分区>

我在这个类的protected 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];

lambda函数,

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; };

所以问题来了。我遇到了这些错误:

 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 channel Bisqwit 在他的俄罗斯方 block 游戏中。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com