重複の可能性:
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との間に競合があることを詳しく説明してくださいl13l12const - 些細な質問で本当にすみません