我無法解釋自己以下代碼:關於C++中const指針的問題?
double d = 100;
double const d1 = 30;
double* const p = &d; // Line 1
double* const p1 = &d1; // Line 2
在上面的代碼,Line 1
是好的,但Line 2
產生錯誤:
"error C2440: 'initializing' : cannot convert from 'const double *__w64 ' to 'double *const '"
誰能詳細說說嗎?我正在使用VS C++ 2005,在Win XP SP3上運行)
請閱讀:http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.5 –