可能性の重複:
Difference between const declarations in C++constキーワード位置
#include <iostream>
class Bar{};
void foo(const Bar x){} //l5
void foo(Bar x){} //l6
void foo(Bar const x){} //l7
////pointer functions
void foo(const Bar* x){} //l11
void foo(Bar* x){} //l12
void foo(Bar* const x){} //l13
コンパイラ出力:(長い話を短くl5
、l6
、l7
紛争;だけl12
、l13
紛争)
untitled.cpp:6:6: error: redefinition of ‘void foo(Bar)’
untitled.cpp:5:6: error: ‘void foo(Bar)’ previously defined here
untitled.cpp:7:6: error: redefinition of ‘void foo(Bar)’
untitled.cpp:5:6: error: ‘void foo(Bar)’ previously defined here
untitled.cpp:13:6: error: redefinition of ‘void foo(Bar*)’
untitled.cpp:12:6: error: ‘void foo(Bar*)’ previously defined here
何が起こっていますか?
- 宣言のそれぞれの意味は何ですか
- なぜ、すべての3つの宣言オブジェクト機能との競合だけで2ポインタ機能付き?
- は
l12
がconst
キーワードが含まれていないにもかかわらず、その競合がl12
とl13
との間にある手の込んだしてください - 本当に申し訳ありませんかの些細な質問 あなたが前に、またはタイプ名の後のconstを置くかどうかは関係ありません
最初の文章:この特定の文脈では、コンパイラには関係ありません。しかし、一般的に、 'const'は先行するものを変更し、' const'を変更した後に体系的に(const intではなく 'int const')、コードを読みやすくします。 –