【发布时间】:2015-05-09 02:17:38
【问题描述】:
在 SFML 教程中,据说当您执行以下操作时纹理会被破坏:-
sf::Sprite loadSprite(std::string filename)
{
sf::Texture texture;
texture.loadFromFile(filename);
return sf::Sprite(texture);
} // error: the texture is destroyed here
当正确返回时,纹理是如何在那里被破坏的?
【问题讨论】:
-
您需要了解构造函数、析构函数、它们的作用以及它们何时运行。在这种情况下,
texture的析构函数会在变量超出范围时执行,无论这种情况如何发生。