私はこのコードを持っています:
template <class T>
class Something
{
T val;
public:
inline Something() : val() {}
inline Something(T v) : val(v) {}
inline T& get() const { return val; }
inline Something& operator =(const Something& a) { val = a.val; return *this; }
};
typedef Something<int> IntSomething;
typedef Something<const int> ConstIntSomething;
class Other
{
public:
IntSomething some_function()
{
return IntSomething(42);
}
ConstIntSomething some_function() const
{
return ConstIntSomething(42);
}
};
void wtf_func()
{
Other o;
ConstIntSomething s;
s = o.some_function();
}
ただし、コンパイラはOther::some_function()
inの間違ったオーバーロードwtf_func()
(つまり、非 const のもの) を選択します。どうすればこれを修正できますか? の名前を変更できない理由があることに注意してくださいOther::some_function()
。