有人可以解釋爲什麼允許第二次轉換,而第一次轉換不允許?他們都可能允許一個const左值的修改...C++資格轉換 - 常量
double *wPtr;
const double ** wRef = &wPtr;
const double * const * wRef = &wPtr;
謝謝 單組
添加編譯從科莫錯誤...
int main(int argc, const char* argv[])
{
double *wPtr;
const double ** wRef = &wPtr;
return 0;
}
Compiling Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 4: error: a value of type "double **" cannot be used to
initialize an entity of type "const double **"
const double ** wRef = &wPtr;
^
1 error detected in the compilation of "ComeauTest.c".
您可以發佈編譯此代碼時得到的錯誤消息的示例嗎?我認爲別的什麼可能會發生...... – Anton 2011-04-25 02:48:33
@antonm:不,他是正確的,第一個構成了一個明確的和編譯器捕獲的錯誤,第二個沒有。他只是沒有第二個的含義。 – 2011-04-25 02:55:06
@尼古拉斯:是的,我現在看到它。有人(你?)發佈了一個答案,我再也看不到了。它有這個有用的鏈接:http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17 – Anton 2011-04-25 03:08:17