中級 › C++でerror: assignment of read-only variable が出る原因と直し方 › パターン5
C++でerror: assignment of read-only variable が出る原因と直し方
constを付けて宣言した変数に、あとから値を代入しようとしたときに出るエラーです。
1 #include <iostream> 2 int main() { 3 const double rate = 0.05; 4 ____________ = 0.1; ^ 5 std::cout << rate << std::endl; 6 return 0; 7 }
main.cpp:4:10: error: assignment of read-only variable 'rate'
空欄を埋めてコンパイル・実行を通す
double型のconst変数でも同様です。名前への代入はコンパイル時に検出されます。
次の問題