首页 > 解决方案 > 需要帮助找出正确的语法来更新全局范围内的对象

问题描述

我有这个代码:

int do_transact(ifstream & inFile, list<shared_ptr<Bike>> bikelist, status s)
{
    int id, i = 0, size = bikelist.size();
    float days;
    string str, str2;
    char name[50];
    list<shared_ptr<Bike>>::iterator it = bikelist.begin();


    if (s == NO_STATUS) //performs rental
    {
        inFile >> id;
        inFile >> days;

        inFile >> str;
        inFile >> str2;
        strcpy_s(name, str.c_str());


        while (i < size)
        {
            if (id == (*it)->id_num) // rents bike
            {
                cout << "vvvvvv PERFORMING RENTAL vvvvvv" << endl << endl;
                cout << "The price of this rental will be: $" << (days)*((*it)->cost_per_day) << endl;
                strcpy_s((*it)->to_whom, name);
                (*it)->rented_code = RENTED;
                cout << "Thank you for your business!" << endl << endl;
                return 0;
            }

            i++;
            it++;
        }
    }
}

我正在尝试更改原始列表to_whomrented_code但它没有更新。

为了以我需要的方式更改这些值,我需要什么语法?

标签: pointersscopeiteratorgloballocal

解决方案


推荐阅读