1

のような非会員オペレーターを持つことは可能ですか?

bool operator==(const std::string &l, const Token r)

無関係なクラスのプライベートメンバー関数としてInterpreter?当然の方法で試しましたが、うまくいきません (引数が多すぎます)。私は知っています、すでに「メンバーとしての非メンバー関数[...]」というタイトルは反対を言っていますが、関数よりも良い方法はありますか

bool isToken(const std::string &l, const Token r)

の(非静的)メンバーに依存する比較を行うにはInterpreter

Tokens をstringの外でsと比較することはできませんInterpreter

いくつかの追加情報: トークンは列挙型であり、比較は の構築時に設定された言語に依存しInterpreterます。

4

2 に答える 2

0

Since comparison is made by a non-static member of Interpreter (say, is_equal()), you need three objects to make a comparison: an Interpreter, a string, and a Token.

If you know there is exactly one valid Interpreter object instance at the time of comparison, you could have this instance made accessible statically, e.g.

bool operator==(const std::string &l, const Token r)
{
   return Interpreter::instance().is_equal(l, r);
}

where static member instance() returns the Interpreter object that does the work.

于 2013-08-31T01:29:41.300 に答える