2
비교 함수에 대한 인수를 집합으로 사용하는 생성자를 전달할 수 있는지 궁금합니다. 이런인수를 취하는 생성자를 C++의 집합으로 전달할 수 있습니까?
예를 들어 어떤 다음 Compare
개체의 타입은 std::set
또는 두 번째 인수
explicit set (const Compare& comp = Compare(),
const Allocator& = Allocator());
이다
class cmp
{
private:
string args_;
public:
cmp(const string& s):args_(s){}
bool operator()(const int & a, const int& b)
return a<b;
}
int main(int argc, char * argv[])
{
string s(argv[1]);
multiset<int, cmp(s)> ms; //can i do this?
}
그래서'multiset ms (cmp (s));'가됩니다. –
오, 그 근무하지만, 나는 그것을 사용하여 멀티 세트에 삽입 할 수 있습니다 – user798774