エラーが発生します:
エラー: タイプ 'std::string& {aka std::basic_string&}' の非 const 参照の初期化が無効です タイプ '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
}