在SFML教程,它是說,當你做這樣的事情的質地被破壞: -紋理在以下情況下如何被破壞?
sf::Sprite loadSprite(std::string filename)
{
sf::Texture texture;
texture.loadFromFile(filename);
return sf::Sprite(texture);
} // error: the texture is destroyed here
質地如何摧毀那裏,當它返回正確?
您需要了解構造函數,析構函數,它們的功能以及運行時間。在這種情況下,當變量超出範圍時,「texture」的析構函數會執行,而不管這種情況如何。 – Nemo