3
我已經得到了包括從C++應用程序使用了一些C代碼複製const的錯誤,這裏最重要的部分:用C++封裝C代碼
C代碼
ifdef __cplusplus
extern "C" {
endif
...
typedef void* problem_type;
...
int problematic_fn_proto(const problem_type const arg);
ifdef __cplusplus
}
endif
不幸的是,由於duplicate 'const'
錯誤,這不會編譯。這是導致問題的typedef
。如果我只是將功能原型更改爲:
int problematic_fn_proto(const void* const arg);
沒有更多問題。很遺憾,我無法刪除typedef
。這裏有解決方案嗎?我可以對C部分進行其他更改,但typedef和它用作函數的參數必須保留。
注意兩個'常量problem_type'和'problem_type const'是'無效* const'的別名,而不是'常量無效* const'。 – cpplearner
@creamarner請解釋。說const const void意味着地址和地址指向的值是不可變的,是正確的嗎? – DaveyLaser
查看任何C++ FAQ,它應該解釋指針到常量和常量指針之間的區別。這就是說,爲什麼你不能修復代碼? –