私は演習として Complex クラスを実装しており、このファイルをガイドラインとして見ています。
このファイルのある時点で、オーバーロードされた奇妙な演算子を見つけました。
template<typename _Tp>
inline complex<_Tp>
operator+(const complex<_Tp>& __x, const _Tp& __y)
{
complex<_Tp> __r = __x;
__r.real() += __y;
return __r;
}
__r.real()
としてどのように使用できlvalue
ますか?の2つのオーバーロードされた定義とともに、クラスに実装しようとしましたreal()
が、もちろん、多くのエラーが返されます。
誰かが私に欠けているものを教えてもらえますか?
これらは関数real()
との定義ですimag()
:
template<typename _Tp>
inline _Tp&
complex<_Tp>::real() { return _M_real; }
template<typename _Tp>
inline const _Tp&
complex<_Tp>::real() const { return _M_real; }
template<typename _Tp>
inline _Tp&
complex<_Tp>::imag() { return _M_imag; }
template<typename _Tp>
inline const _Tp&
complex<_Tp>::imag() const { return _M_imag; }