比较存储在对象数组中的字符串

时间:2013-10-10 22:31:44

标签: c++ arrays string object string-comparison

我正在尝试使用插入排序按字母顺序对名称列表进行排序,为此我需要比较两个对象数组,但是当我使用标准字符串库函数compare时,编译器会将其解释为喜欢访问我的类的数据成员,实际上我想访问包含该字符串的类的数据成员。

void Course::sortRow(int RowtoSort)
{
    int i, j;

    Student bucket; 

    for(i = 1; i < enrolled[RowtoSort];i++)
    {
        //assign bucket with temp value for swap
        bucket = Students[RowtoSort][i]; 

        for(j = i;
            (j > 0) && (Students[RowtoSort][j-1].compare(bucket)) < 0;
            j--) //how would I compare the two arrays of objects?
            {
                //assign j to element j-1 so now both j and j-1
                // are the same in the array
                Students[RowtoSort][j] = Students[RowtoSort][j-1]; 
            }

            //now j-1 value is at j and since j-- assign it
            // to bucket to place the proper value at j-1  
            Students[RowtoSort][j] = bucket;
        } // end outer loop
    }

我如何将两个对象Students[RowtoSort][i]与Bucket进行比较?

0 个答案:

没有答案