g++ コンパイラは次のことについて不平を言います:
error: no matching function for call to ‘AddressSpace::resolve(ClassOne&, ClassTwo*&, ClassThree&) const’
note: candidates are: bool AddressSpace::resolve(ClassOne&, ClassTwo*, ClassThreer) <near match>
このエラーの原因となっているコードは
void Class::handler(ClassOne& objOne, ClassTwo& objTwo,
ClassThreer objThree) {
obj.getAddressSpaceObj().resolve(objOne, objTwo.pointer, objThree);
}
コードを調べたところ、このエラーは によって返された参照型が原因であることがわかりましたgetOtherObj()
。クラス定義で AddressSpace オブジェクトへの const 参照を返すようにします。
const AddressSpace &getAddressSpaceObj(){
return addressSpace;
}
この定義を通常の参照を返すように変更した後、
AddressSpace &getAddressSpaceObj(){
return addressSpace;
}
コンパイラはもう文句を言いません。なぜこのエラーがパラメータの不一致エラーとして宣言されているのだろうか? コンパイラがコンテンツを関数呼び出しのパラメーターとしてコピーせず、参照として渡したのはなぜですか?