0

我的 C++ 代码有问题,因为 valgrind 在下面突出显示的行中给了我错误(条件跳转或移动取决于未初始化的值)。我尝试用空字符串初始化“ type ”,但似乎没有用。非常感谢这里的任何帮助。

提前谢谢了。

南达纳塔尔

int AB_CD::checkType(string & str)
{
    int tmp = 0;

    string type;


    while (getNextSubstring(str, type))
    {
        if (type == "AAA")     <<<<< ----- Valgrind error pointing here 
        {
            tmp |= static_cast<int>(TYPE_AAA);
        }
        else if (type == "BBB") <<<<< ----- Valgrind error pointing here 
        {
            tmp |= static_cast<int>(TYPE_BBB);
        }
        else if (type == "CCC") <<<<< ----- Valgrind error pointing here 
        {
            tmp |= static_cast<int>(TYPE_CCC);
        }
        else
    {
        //Print a warning
    }

    }

    return tmp;

}



bool AB_CD::getNextSubstring(string & input, string & substring)
{
    bool found_substring = false;

    string::size_type start = input.find_first_not_of(" ,");
    string::size_type end = input.find_first_of(" ,", start);

    if (start != string::npos)
    {
        substring = input.substr(start, end-start);
        input.erase(start, end-start);
        found_substring = true;
    }
    return found_substring;
}
4

0 回答 0