SFGUI에서 SFGUI를 사용하기 시작 했으므로 모든 것을 이해하는 데 어려움을 겪고 있습니다. 필자는 hello world 튜토리얼과 라이브러리 자체가 제공하는 몇 가지 예제를 통해 폴더를 읽었습니다.SFGUI에서 OnClick 함수에 간단한 버튼을 바인딩하려고 시도했습니다.
왼쪽 버튼을 감지했을 때 무언가를하는 간단한 버튼을 만들려고하고 있는데 제대로 작동하지 못합니다. 오류 창에 OnClick
메서드에서 button
변수가 정의되어 있지 않으며 std::bind
매개 변수를 사용하여 button
을 보내려고하면 "no matching function for ..."이 표시됩니다.
라이브러리의 대부분의 예제에서이 문제는 두 번째 매개 변수로 함수 이름 옆에 this
을 사용하여 해결되지만 저에게는 효과적이지 않은 것으로 보입니다.
어떻게해야합니까?
내 코드 :
void pressEnter(){
button->SetLabel("Tocado"); // FIRST ERROR IN THIS LINE
}
int main(){
sfg::SFGUI sfgui;
sf::VideoMode video_mode(800, 600);
sf::RenderWindow rwindow(video_mode, "In-joked - Menu Principal");
sf::Event event;
auto button = sfg::Button::Create("Status");
button->GetSignal(sfg::Button::OnLeftClick).Connect(
std::bind(&pressEnter, button)); //SECOND ERROR IN THIS LINE
...
}
오류 NetBeans는 첫 번째 라인을 보여줍니다. "" 버튼 "식별자를 확인할 수 없습니다"버튼 "이 범위에서 선언되지 않았다"
그리고에 대한 두번째 라인 :
"파일은
오류를 포함 : SFG '에 통화 기능과 일치 :: :: 신호 연결 (표준 : 0 _ Bind_helper> :: type) ' std :: bind (& pressEnter, button)); " 실행 콘솔 출력에
전체 오류 :
main.cpp: In function ‘void pressEnter()’:
main.cpp:7:5: error: ‘button’ was not declared in this scope
button->SetLabel("Tocado");
^
In file included from /usr/include/c++/5/memory:79:0,
from /usr/local/include/SFGUI/Signal.hpp:6,
from /usr/local/include/SFGUI/Object.hpp:4,
from /usr/local/include/SFGUI/Adjustment.hpp:3,
from /usr/local/include/SFGUI/Widgets.hpp:6,
from main.cpp:2:
/usr/include/c++/5/functional: In instantiation of ‘struct std::_Bind_check_arity<void (*)(), std::shared_ptr<sfg::Button>&>’:
/usr/include/c++/5/functional:1439:12: required from ‘struct std::_Bind_helper<false, void (*)(), std::shared_ptr<sfg::Button>&>’
/usr/include/c++/5/functional:1462:5: required by substitution of ‘template<class _Func, class ... _BoundArgs> typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...) [with _Func = void (*)(); _BoundArgs = {std::shared_ptr<sfg::Button>&}]’
main.cpp:20:42: required from here
/usr/include/c++/5/functional:1410:7: error: static assertion failed: Wrong number of arguments for function
static_assert(sizeof...(_BoundArgs) == sizeof...(_Args),
^
main.cpp: In function ‘int main()’:
main.cpp:20:43: error: no matching function for call to ‘sfg::Signal::Connect(std::_Bind_helper<false, void (*)(), std::shared_ptr<sfg::Button>&>::type)’
std::bind(&pressEnter, button));
^
In file included from /usr/local/include/SFGUI/Object.hpp:4:0,
from /usr/local/include/SFGUI/Adjustment.hpp:3,
from /usr/local/include/SFGUI/Widgets.hpp:6,
from main.cpp:2:
/usr/local/include/SFGUI/Signal.hpp:40:16: note: candidate: unsigned int sfg::Signal::Connect(std::function<void()>)
unsigned int Connect(std::function<void()> delegate);
^
/usr/local/include/SFGUI/Signal.hpp:40:16: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (*)(), std::shared_ptr<sfg::Button>&>::type {aka std::_Bind<void (*(std::shared_ptr<sfg::Button>))()>}’ to ‘std::function<void()>’
nbproject/Makefile-Debug.mk:78: recipe for target 'build/Debug/GNU-Linux/main.o' failed
make[2]: *** [build/Debug/GNU-Linux/main.o] Error 1
make[2]: Leaving directory '/home/manu/NetBeansProjects/GameMenu'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/manu/NetBeansProjects/GameMenu'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 953ms)
'std :: bind'는'pressEnter' 함수가 호출 될 때'button' 변수를 인자로 전달하도록합니다. 그럼에도 불구하고 당신의 기능은 어떤 주장도하지 않습니다. –
나도 알아? 내가 시도한 첫 번째 일은 'pressEnter'가 매개 변수를 받도록 설정하는 것이 었습니다. 이상하게 보였으 나 작동하지 않았습니다. 또한 자습서는 이러한 방식으로 유지합니다. – Manu
오류가 발생하면 먼저 오류를 나타내는 코드가 표시됩니다. 또한 가능한 실제 정보를 포함하여 실제 오류를 모두 포함 시키십시오. 잠시 시간을내어 [좋은 질문을하는 법을 읽어보십시오] (http://stackoverflow.com/help/how-to-ask). –