gpt4 book ai didi

c++ - 初始化类构造函数

转载 作者:行者123 更新时间:2023-11-30 02:02:29 25 4
gpt4 key购买 nike

我有一些类似的代码

// Includes, namespace and prototypes
#include "template.h"
#include "Global.h"
#include "Sprite.h"
#include "Gesture.h"
#include "Touch.h"


using namespace AGK;

Gesture currentGesture;

// Begin app, called once at the start
void app::Begin( void )
{
SetupEnvironment(ENV_ANDROID);
CreateBackground();
}

我如何在此上下文中调用 currentGesture 的构造函数以便我可以使用它?我知道它不是通过在 app::Begin 上定义它来调用的。

最佳答案

事实上,它是。

Gesture currentGesture;

定义一个名为 currentGesture 的变量,具有外部链接和全局作用域。构造函数在进入 main 之前被调用,因此到那时该变量仍然有效。您可以在此翻译单元中将其用作 currentGesture::currentGesture

其他翻译单位必须先声明:

extern Gesture currentGesture;

关于c++ - 初始化类构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13107262/

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