演繹類型時,我聲明如下常量: const auto val = someFun();
現在我想用同一類型的「VAL」的,但沒有固定規範的另一個變量。 decltype(val) nonConstVal = someOtherFun();
// Modify nonConstVal, this is error when using decltype
當前decltype保持常量。如何去除
今天我看到一些像這樣的代碼: int a = 0;
const decltype((a)) x = 10; // Error
const int b = 0;
decltype ((b)) y = 42; // Correct
我可以看到爲什麼正確的代碼是正確的,但我不明白爲什麼不正確的代碼不正確。 我測試了一下,發現它有點奇怪。 const decltype((a)) x = 10;