天天看點

std :: sort與本地類型比較

這是代碼片段:

#include <iostream>
#include <algorithm>
#include <vector>

struct AdItem {
	std::string ad_id;
	int priority;
	int score; 
};

void AdSort(std::vector<AdItem> &ad_items) {
	
	std::sort(ad_items.begin(), ad_items.end(), [](const AdItem &item1, const AdItem &item2) {
		if (item1.priority < item2.priority) {
			return true;
		}
		else if (item1.priority > item2.priority) {
			return false;
		}
	
		return item1.score >= item2.score;
	});
}

int main()
{
    std::cout << "Hello World!\n";
	std::vector<AdItem> v;

	AdSort(v);

	return 0;
}

           

報錯:

std :: sort與本地類型比較

上述用編譯GCC 4.8使用

g++ -Wall -c mysort.cc

我得到了同樣的錯誤

g++ -std=c++03 -Wall -c test.cc

或者

g++ -std=c++98 -Wall -c test.cc

但沒有錯誤

g++ -std=c++11 -c test.cc
           

鑒于我g++ -v是一個gcc version 4.8.2 (Debian 4.8.2-12)

但是用Clang/LLVM 3.4編譯

clang++ -Wall -c test.cc

繼續閱讀