Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
たとえば jQuery では、関数をカプセル化して、オブジェクトに対して多くのアクションを 1 行で実行できます。
$('div').parent().find('a').is('.class').css('color', 'red');
それが内部でどのように機能するかはわかりません。同様の動作で C++ でクラスを作成するにはどうすればよいですか?
これはメソッド チェーンと呼ばれ、戻り値の型に応じて、C++ でも同じ効果を得ることができます。
struct A { A& foo() { return *this; } A& goo() { return *this; } }; A a; a.foo().goo().foo();
これは簡単な例です。