2
對於我的生活,我無法獲得此代碼的工作。我試圖將我的代碼從C#轉換爲C++,但棄用了XNA框架,但一個固執的方法並不想被轉換。在C#中,它是:C++ std :: find lambda表達式
public Tile GetTileAtPosition(bool screenOrGame, Vector2 position)
{
if (screenOrGame)
{
return Array.Find(tileList, tile => tile.Position == position/24);
}
else
{
return Array.Find(tileList, tile => tile.Position == position);
}
}
在C++中,我試圖取代這一使用的代碼是:
Tile Level::GetTileAtPosition(bool screenOrGame, sf::Vector2f position)
{
vector<Tile>::iterator it;
if (screenOrGame)
{
it = find(tileList.begin(), tileList.end(), [position](const Tile &t) { return t.GetPosition() == sf::Vector2f(position.x/24, position.y/24); });
return Tile(it->GetID(), it->GetPosition().x, it->GetPosition().y);
}
else
{
it = find(tileList.begin(), tileList.end(), [position](const Tile& t) { return t.GetPosition() == position; });
return Tile(it->GetID(), it->GetPosition().x, it->GetPosition().y);
}
}
在C++分配行(它= ...)我得到一個痛苦的錯誤,我無法找出原因或解決方案。它返回:
error C2679: binary '==' : no operator found which takes a right-hand operand of type 'const Blobby::Level::GetTileAtPosition::<lambda_29eb981cd341d9c05d39c4654bc470b9>' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility 3186
有沒有什麼辦法來解決這個錯誤,或者實現C++中的方法更好/更實際的方法是什麼?
試試'std :: find_if'。 – chris
你是我的英雄。 – Oracular