をサポートしていないようであるWindows 7の下に、最新のQT IDE(boost.1.48)ブーストshared_ptrのは、ここでオペレータ==
class Employee {
public:
int Id;
...
bool operator==(const Employee& other) {
qDebug() << this->Id << ":" << "compare with " << other.Id;
return this->Id==other.Id;
}
}
テストコード上で実行される:
Employee jack1;
jack1 == jack1; // the operator== gets invoked.
shared_ptr<Employee> jack(new Employee);
jack == jack; // the operator== doesn't get invoked.
関連ブーストヘッダファイル内のコードは次のとおりです。
template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
{
return a.get() == b.get();
}
比較ポインターを行う代わりに、私はそれを期待やっているようです。
どうすればいいですか?
を除いて。 'operator =='を 'const'メンバ関数にすることを考慮してください。 'operator =='を2つの 'const'参照を取るフリー関数にすることを検討してください。 –