1. 程式人生 > >char *與const char **函數參數傳參問題

char *與const char **函數參數傳參問題

函數參數 http quest stack cast ... 參數 code -c

傳參方法

## 函數

extern void f2 ( const char ** ccc );


const char ch = 'X';
char * ch_ptr;
const char ** ch_pptr = &ch_ptr; // This is not allowed, because...

## 傳參

f2(ch_ptr)

## 如果遇到報錯

f2(const_cast<const char**>(ch_ptr));

參考

const char * vs. const char ** function argument [duplicate]

https://stackoverflow.com/questions/32096734/const-char-vs-const-char-function-argument
c++: why can‘t we convert char ** to const char ** [duplicate]
https://stackoverflow.com/questions/32779079/c-why-cant-we-convert-char-to-const-char

char *與const char **函數參數傳參問題