且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误C2280:尝试引用已删除的函数

更新时间:2022-04-29 09:16:23

$ c> Pad 或 Ball (或两者)没有默认构造函数;因此不能为包含它们的类生成一个。

Presumably, either Pad or Ball (or both) has no default constructor; therefore one can't be generated for a class that contains them. They must be initialised using one of their declared constructors.

***的解决方法是删除你的奇怪的 init 函数,并用构造函数替换它:

The best solution is to remove your weird init function, and replace it with a constructor:

ArkanoidGame(int windowWidth, int windowHeight) :
    running(true),
    window(new ...),
    Pad(windowWidth / 2, windowHeight - 50),
    Ball(0,0)
{
    window->setFramerateLimit(60);
}

int main() {
    ArkanoidGame game(800, 600);
    // ...
}

阶段初始化舞蹈的某些原因,那么你需要为 Pad Ball 提供默认构造函数。我不会推荐,虽然;如果无法在无效状态下创建对象,则出现错误的可能性较小。

If you really want a two-stage initialisation dance for some reason, then you'll need to provide default constructors for both Pad and Ball. I wouldn't recommend that though; there's less scope for errors if an object can't be created in an invalid state.