为什么我在以下功能中出错?

时间:2017-07-02 00:49:21

标签: c++

我有以下功能:

ubigint::ubigint (const string& that){
           DEBUGF ('~', "that = \"" << that << "\"");
           for (char digit: that) {
              if (not isdigit (digit)) {
                 throw invalid_argument ("ubigint::ubigint(" + that + ")");
              }
           }

           //string thatCopy = that;

           for(string::reverse_iterator rit = that.rbegin(); rit != that.rend(); rit++) // iterate the string from end to start and store it in the vector
            {
                ubig_value.push_back(*rit); // push the character
            }  


        }

我收到以下错误

 error: no matching function for call to ‘__gnu_cxx::__normal_iterator

我在函数中创建了一个字符串的副本,这解决了问题

ubigint::ubigint (const string& that){
   DEBUGF ('~', "that = \"" << that << "\"");
   for (char digit: that) {
      if (not isdigit (digit)) {
         throw invalid_argument ("ubigint::ubigint(" + that + ")");
      }
   }

   string thatCopy = that;

   for(string::reverse_iterator rit = thatCopy.rbegin(); rit != thatCopy.rend(); rit++) // iterate the string from end to start and store it in the vector
    {
        ubig_value.push_back(*rit); // push the character
    }  


}

为什么会这样?我不允许迭代常量字符串吗?

0 个答案:

没有答案