[cppll:13000] Re: std::map のキーにオブジェクトのインスタンスを使用する

Subject:
[cppll:13000] Re: std::map のキーにオブジェクトのインスタンスを使用する
From:
cb <sumiaki@...>
Date:
Fri, 15 Jun 2007 19:47:21 +0900
X-Mailer:
Denshin 8 Go V32.1.5.3 on Windows 5.01.2600 Service Pack 2
Message-Id:
<200706151047.l5FAlMSR025729‐at‐mx55.ms.so-net.ne.jp>
In-Reply-To:
12998
References:
12985 12986 12990 12995 12998
cbです。


> 演算子の両辺が異なる型のとき、メンバ関数では対応できなくなることがあります。
>
> class String {
> public:
>   bool operator==(const char* rhs);
>   ...
> };
>
> なんて定義だと x == "ほげ" できるけど "ほげ" == x できんです。
>
ああ、ありましたね。

bool operator == ( const String& srcL, const char& srcR ) { }
bool operator == ( const char* srcL, const String& srcR ) { }
としておけば、両方に対応できるってやつですね。

スレッド

Navigation

検索

[検索ヘルプ]

Maintener: Tietew <www.tietew.jp>
Powered by Ruby on Rails, Mongrel, PostgreSQL, and Hyper Estraier.
click here