将 sf::Texture 存储在 dll 中的静态变量中

Store sf::Texture in a static variable in a dll

实际上我使用 dll 将一些方法导出到非托管应用程序。

我需要为 sf::Texture 创建一个静态变量,但是当我尝试时,dll 没有正确初始化。

我只是添加了这一行:

static Texture test3;

然后 dll 停止。

关于 "static" 作为限定词的影响,这些在其他答案中都有介绍。如果你想使用 "static" 那么你应该知道 "static" 在做什么。

In a C++ namespace does the `static` qualifier have any effect when prefixing non-member subroutines declared in the header?

我不知道您想要实现什么,但我认为您可能希望通过 DLL 中定义的函数访问该值。

例如

source.cpp

static Texture *myInternalTexture;

void InitInternalTexture(){
    myInternalTexture = new Texture( blah);
}

Texture *GetInternalTexture(){
    return myInternalTexture;
}

void ReleaseInternalTexture(){
    delete myInternalTexture;
}

根据您的使用情况,您可能更喜欢访问纹理的参考或复制,我不知道您需要做什么。如果您可以轻松调整上面的代码以使用您的纹理类型。