検索結果 3 件

by Sx1752
13年前
フォーラム: C言語何でも質問掲示板
トピック: ラムダ式での比較演算子
返信数: 5
閲覧数: 3093

Re: ラムダ式での比較演算子

h2so5 さんが書きました:ソート中に a, b を変更してはいけないので、コンパイルできないのは仕様です。
仕様でしたか。お答えいただきありがとうございました。
by Sx1752
13年前
フォーラム: C言語何でも質問掲示板
トピック: ラムダ式での比較演算子
返信数: 5
閲覧数: 3093

Re: ラムダ式での比較演算子

お示しのコードはコンパイルに失敗するコードですか?それとも成功するコード? ここに貼ったのは成功するコードです。 [](const Item& a, const Item& b) { return a < b; } ここの引数の宣言がconstだからじゃないでしょうか? どうやらそのようですね。ラムダ式の [](Item& a, Item& b) { return a < b; } を [](Item a, Item b) { return a < b; } に変更するとコンパイルできました。 しかし、a, bを参照型にするとやっぱりコンパイル出来ないです。 #include <cstrin...
by Sx1752
13年前
フォーラム: C言語何でも質問掲示板
トピック: ラムダ式での比較演算子
返信数: 5
閲覧数: 3093

ラムダ式での比較演算子

#include <cstring> class Item { private: int id; char name[32]; public: Item(const int id = 0, const char *name = nullptr) { this->id = id; if(!name) ::strcpy(this->name, ""); else ::strcpy(this->name, name); } const int getId() const { return id; } const char* getName() const { return name; } bool...

詳細検索ページへ移動する