아래 예제 코드에서 오버로드 된 연산자 < const 정규화 된 및 Visual C++에서 (모든 버전에서 2013 년 미리보기까지) 컴파일하지만 Clang , 그것은 오류를 던집니다 - 참고 : 후보 함수가 실행 가능하지 않습니다 : 'this'인수는 'const Entry'유형이지만 메서드는 const bool 연산자 < (const 항목 & 기타)으로 표시되지 않습니다. Visual C++ 관계 연산자 오버로드 const 정확성 (std :: sort 함께)
#include "stdafx.h"
#include <vector>
#include <algorithm>
struct Entry
{
unsigned int age;
bool operator<(const Entry& other) // !!! no const qualification here !!!
{
return age < other.age;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<Entry> entries;
for(unsigned int i = 0; i < 100; ++i)
{
Entry entry;
entry.age = i;
entries.push_back(entry);
}
// Sort by age
std::sort(entries.begin(), entries.end());
return 0;
}
는/관계 연산자 비교의 CONST-정확성을 시행 비주얼 C++되지 표준 순응인가? 아니면 std :: sort와 관련이 있습니까?
아마도'std :: sort' 구현 문제 : clang은'const' 컨텍스트에서 객체를 비교하고 VC++는 그렇지 않습니다. 일반적으로 clang과 VC++가 동의하지 않으면 VC++의 구현에 오류가 있기 때문입니다. :) – Yakk