看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) WIN10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) A.cpp double* m_Matrix; m_Matrix = new double[16]; const double *t_refer = m_Matrix; //指向常數的指標 GetMode(t_refer); B.cpp double* m_SecMatrix; m_SecMatrix = new double[16]; GetMode(const double* &m_matrix) { m_matrix = m_SecMatrix; } 補充說明(Supplement): 想請問各位前輩這個程式片段 指向常數的指標改變指標是合法的 為什麼B.cpp 裡要用 & 的符號呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.127.200.146 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1541041767.A.A81.html
jerryh001: &和你要問的問題無關吧 沒&傳進來的是double的位置 有& 11/01 11:18
jerryh001: 傳進來的才是那個指標變數 11/01 11:18
前輩解釋後 我突然意識到是傳參考呼叫 因為加上了CONST 搞得我有點混亂 謝謝前輩 ※ 編輯: asdfg1597860 (59.127.200.146), 11/01/2018 12:01:02
SWQLovE: double *const ptr 跟 const double *ptr 11/05 04:09
SWQLovE: 他是指向常數變數的指標 不是指向變數的常數指標 11/05 04:10