나는() 연산자를 오버로드하여 비교를 수행했으며이를 표준 정렬 함수 호출의 세 번째 인수에 비교 자로 보내려고합니다. 이제이 호출은 threeSum
이라는 다른 멤버 함수에 있습니다. 그걸 보내면 Solution()
이 작동하지만 this()
은 작동하지 않습니다. 이 구문 규칙은 무엇입니까?같은 클래스의 다른 멤버 함수에서 펑터를 호출하는 방법은 무엇입니까?
class Solution
{
public:
bool operator() (int i, int j)
{
return (i < j);
}
vector<vector<int> > threeSum(vector<int> & nums)
{
sort(nums.begin(), nums.end(), this());
vector<vector<int> > ret_vec;
...
return ret_vec;
}
};
고맙습니다.
비교기를 사용해야하는 곳은 어디입니까? – simplename
'bool operator() (int i, int)와 같이 연산자를'const'로 만들 필요가 있습니다. j) const {...}' –