我收到一个错误:
错误:从“std::basic_string”类型的右值对“std::string& {aka std::basic_string&}”类型的非常量引用无效初始化
代码是:
const std::string& hitVarNameConst = (isKO ? "isKO" : "isKI");
for (int i = 0; i < numAssets; i++){
std::string& hitVarName1 = hitVarNameConst + Format::toString(i + 1);
//use hitVarname1 with some other function
}
如何消除此错误?早些时候我尝试了以下代码,它仍然抛出相同的错误:
for (int i = 0; i < numAssets; i++){
std::string& hitVarName1 = (isKO ? "isKO" : "isKI") + Format::toString(i + 1);
//use hitVarname1 with some other function
}