c ++ visual studio windows形成可能的范围问题

时间:2015-12-07 08:51:55

标签: c++ visual-studio

制作一款游戏,根据所拥有的企业,金钱每秒递增一次。当业务被出售但是没有时,金钱应该停止递增。以下是所涉及的所有方法。 我想也许删除业务方法不会永久删除它,任何想法?

uname.sell(name);
uname.addMoney(sellValue);

void User::sell(std::string b)
{
    Business temp = this->current.getBusiness(b);

    this->addMoney(temp.getCost() * 0.8);
    this->getCurrent().removeBusiness(temp);
}

//removes business from the map

void Map::removeBusiness(Business b)
{
    for (int i = 0; i < businesses.size(); i++)
    {
        if (businesses[i].getName() == b.getName()) {
            &businesses.erase(businesses.begin() + i);
        }
    }
}

void User::payday()
{
    double paySum = 0;
    // loops through all the stored maps
    for (int i = 0; i < maps.size(); i++)
    {
        std::vector<Business> temp = maps[i].getBusinesses();
        // Go through temp, finding the bus
        for (int j = 0; j < temp.size(); j++) {
        paySum += temp[j].getPay(); // Sum the pay for all business 
        }   
    }
    addMoney(paySum);
 }

0 个答案:

没有答案