API를 만들려고 할 때 MiniGW에 문제가 있습니다. 이것은 MSVC11 (Visual Studio 2012 C++ 컴파일러)에서 잘 작동합니다. 내 컴파일러는 (나는) 올바르게 λ3 오류 메시지를 가지고 결국 QMAKE_CXXFLAGS += -std=c++0x
, 설정됩니다 믿습니다. 좀 더 설명은람다를 std :: function으로 변환하는 데 문제가 있습니다.
:
typedef std::function<bool(Item)> WHERE;//I was attempting to provide an explicit cast, 'auto' works fine in MSVS
Group where(WHERE func);//A simple "foreach boolean" search
에서 전술>
Groups::WHERE where = [](Item & x)-> bool{return x.has("NEW");};
결과를 사용 :
tst_groupstest.cpp:257: error: conversion from 'GroupsTest::groups()::__lambda1' to non-scalar type 'Groups::WHERE {aka std::function}' requested Groups::WHERE where = [](Item & x)-> bool{return x.has("NEW");};
나는 이것이 분명히 밝혀지기를 바랄뿐입니다. 이 프로젝트로 Linux와 Mac을 지원할 계획이므로 나중에이 파일을 빨리 이해하고 싶습니다.
여기에 현재의 해결 방법이 있습니다. 가능한 모든 경우 (람다를 사용하는 API를 설계 한 이유는 명백한 간결한 코드 블록을 사용하는 것이기 때문에)를 멀리하고 싶습니다.
이 섹션 컴파일 (는 람다를 사용하지 않는)
struct lambdaCueListstdFunc{
bool operator()(Groups::Item x)
{
return x.has("NEW");
}
};
/**
* Selects all cues for a particular list
* @brief getCueList
* @param list
* @return a vector of all the cues for this list sorted by number.
*/
std::vector<Groups::Item> CueService::getCueList(std::string list)
{
std::function<bool(Groups::Item)> where = lambdaCueListstdFunc();
// auto where = [&list] (Groups::Item & x) ->
// {
// return x.get(la::cues::List) == list;
// };
std::vector<Groups::Item> result = cues()->where(where).sort(la::cues::NUMBER);
return result;
}
감사를 통과, 당신은 하나를 알아 내기 위해 노력하는 나에게 몇 시간을 저장. –