Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pointers 需要帮助找出正确的语法来更新全局范围内的对象吗_Pointers_Scope_Iterator_Global_Local - Fatal编程技术网

Pointers 需要帮助找出正确的语法来更新全局范围内的对象吗

Pointers 需要帮助找出正确的语法来更新全局范围内的对象吗,pointers,scope,iterator,global,local,Pointers,Scope,Iterator,Global,Local,我有以下代码: 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>>::iterat

我有以下代码:

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++;
        }
    }
}
int do_transact(ifstream&infle,列表bikelist,状态s)
{
int-id,i=0,size=bikelist.size();
浮动天数;
字符串str,str2;
字符名[50];
list::iterator it=bikelist.begin();
如果(s==无状态)//执行租赁
{
infle>>id;
填充>>天;
infle>>str;
infle>>str2;
strcpy_s(名称,str.c_str());
而(iid\u num)//
{

请提供一个。我唯一看到的是
bikelist
是通过值传递的,而不是通过引用传递的,因此创建了列表的副本,但是由于列表只有指针,这不会影响结果,因为代码没有修改
bikelist
本身。通过值传递只是错过了优化。代码正在访问o原始列表所指向的原始
Bike
对象。请调试您的代码,以确保1)
status
实际上是
NO_status
,2)
bikelist
不是空的,3)
infle
包含您期望的输入数据。我无法使用您显示的代码重现问题。ori只要所有输入正确,ginal列表对象将按预期更新。