1
這是lazyfoo的SDL教程的代碼示例。當通過地址返回時,這不會超出範圍嗎? (SDL)
SDL_Surface *load_image(std::string filename) {
//Temporary storage for the image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = SDL_LoadBMP(filename.c_str());
//If nothing went wrong in loading the image
if(loadedImage != NULL) {
//Create an optimized image
optimizedImage = SDL_DisplayFormat(loadedImage);
//Free the old image
SDL_FreeSurface(loadedImage);
}
//Return the optimized image
return optimizedImage;
}
這裏不應該優化圖像當它返回時超出範圍?因爲它是本地的。