我有一个类,我想使用一个preLoad布尔值来防止它在我的循环中被加载两次。
我这样做:
Sprite::Sprite(std::string& imagefile)
{
if(!preload){
if(!texture.loadFromFile(imagefile)){
exit(2);
}
sprite = sf::Sprite(texture);
width = sprite.getLocalBounds().width;
height = sprite.getLocalBounds().height;
preload = true;
}
}
问题是,preload似乎开始true而不是false。变量在类中设置如下:
private:
bool preload;
但是,我需要将它设置为falsefirst 但它不允许我false在标题中为其分配 a 。我该怎么做才能将其设置为false最初?