Ich habe den folgenden Code-Schnipsel:SFML und STL: Was ist falsch an meinem Code?
void RemoveButton::triggerAction(team &team, unsigned int index)
{
switch (mAction)
{
case Action::remove:
{
//team.mTeamMembers.erase(std::remove(team.mTeamMembers.begin(), team.mTeamMembers.end(), team.mTeamMembers.at(index)), team.mTeamMembers.end());
team.mTeamMembers.erase(team.mTeamMembers.begin() + index);
for (unsigned int i = index; i < team.mTeamMembers.size(); i++)
{
team.mTeamMembers[i].mRemoveButton->getText().move(0.0f, -30.0f);
team.mTeamMembers[i].mText.move(0.0f, -30.0f);
}
team.mAddPosition.y -= 30.0f;
break;
}
default:break;
}
}
class team
{
public:
size_t teamNumber;
std::vector<AddButton> mAddButtons;
std::vector<teamRecord> mTeamMembers;
sf::Sprite mBorder;
sf::Text mText;
Selector<AddButton> mAddButtons_Selector;
sf::Vector2f mAddPosition;
Selector<teamRecord> mTeamMembers_Selector;
team(sf::Vector2f borderPosition, sf::Vector2f removeButtonsPosition, sf::Vector2f textPosition, size_t teamNumb, std::string text);
};
Wie sollte ich ein Element aus dem team.mTeamMembers STL Vektor löschen? Die Art, wie ich es mache, führt derzeit zu scheinbar zufälligen Ausführungsfehlern, insbesondere beim Klicken auf das nicht vorhandene Sprite einer gelöschten Schaltfläche. Die kommentierte Zeile, die std :: remove verwendet, wird nicht kompiliert, und ich verstehe nicht warum. Da ich mich verwirrt fühle, a.f. Kann jemand bitte hier etwas Licht scheinen lassen? Hier ist das Buildprotokoll während std :: zu entfernen, wie von einigen Benutzern auf diesem Forum empfohlen:
1>------ Build started: Project: Complex OOP Menus, Configuration: Release Win32 ------
1> RemoveButton.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\algorithm(1454): error C2678: binary '==': no operator found which takes a left-hand operand of type 'teamRecord' (or there is no acceptable conversion)
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(389): note: could be 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(381): note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(373): note: or 'bool std::operator ==(const std::error_code &,const std::error_condition &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(365): note: or 'bool std::operator ==(const std::error_code &,const std::error_code &) noexcept'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception(339): note: or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t) throw()'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception(334): note: or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &) throw()'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception(329): note: or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &) throw()'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\algorithm(1454): note: while trying to match the argument list '(teamRecord, const teamRecord)'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\algorithm(1467): note: see reference to function template instantiation '_FwdIt std::_Remove_unchecked<teamRecord*,_Ty>(_FwdIt,_FwdIt,const _Ty &)' being compiled
1> with
1> [
1> _FwdIt=teamRecord *,
1> _Ty=teamRecord
1> ]
1> ..\Data\Source\RemoveButton.cpp(24): note: see reference to function template instantiation '_FwdIt std::remove<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<teamRecord>>>,teamRecord>(_FwdIt,_FwdIt,const _Ty &)' being compiled
1> with
1> [
1> _FwdIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<teamRecord>>>,
1> _Ty=teamRecord
1> ]
Wenn nicht genügend Informationen hier sind, ich konnte den Github Link zu meinem Projekt veröffentlichen, aber es ist ziemlich groß und Es würde Zeit brauchen, den Code zu durchforsten.
Verbessern Sie den Titel Ihrer Frage, damit sie die Frage beschreibt und anderen in der Zukunft hilft. –
_ "Ich habe die folgenden Codeschnipsel: Wenn es hier nicht genug Informationen gibt, könnte ich den GitHub-Link zu meinem Projekt posten, aber es ist ziemlich groß und es würde Zeit brauchen, den Code zu durchsuchen." _ Das Help Center weist Sie an einen [MCVE] zusammenstellen und präsentieren. –