Przypisanie surowego wskaźnika this do inteligentnego wskaźnika std::shared_ptr
Ostatnio zmodyfikowano 2025-10-31 16:45
tBane Temat założony przez niniejszego użytkownika |
Przypisanie surowego wskaźnika this do inteligentnego wskaźnika std::shared_ptr » 2025-10-31 16:22:17 Witam. Mam następującą funkcję i próbuję przypisać surowy wskaźnik - this do inteligentnego wskaźnika - std::shared_ptr. Oraz próbuję porównać wskaźnik std::shared_ptr z surowym wskaźnikiem this. Jak to zrobić? extern std::shared_ptr < ElementGUI > ElementGUI_pressed;
void NormalButton::handleEvent( const sf::Event & event ) { if( _rect.contains( cursor->_worldMousePosition ) ) { if( const auto * mbp = event.getIf < sf::Event::MouseButtonPressed >(); mbp && mbp->button == sf::Mouse::Button::Left ) { ElementGUI_pressed = this; } else if( const auto * mbr = event.getIf < sf::Event::MouseButtonReleased >(); mbr && mbr->button == sf::Mouse::Button::Left ) { if( ElementGUI_pressed == this ) { click(); } } } }
|
|
tBane Temat założony przez niniejszego użytkownika |
» 2025-10-31 16:45:59 Znalazłem rozwiązanie :-) extern std::shared_ptr < ElementGUI > ElementGUI_pressed;
class NormalButton : InneKlasy , public std::enable_shared_from_this < NormalButton > { .... };
void NormalButton::handleEvent( const sf::Event & event ) { if( _rect.contains( cursor->_worldMousePosition ) ) { if( const auto * mbp = event.getIf < sf::Event::MouseButtonPressed >(); mbp && mbp->button == sf::Mouse::Button::Left ) { ElementGUI_pressed = this->shared_from_this(); } else if( const auto * mbr = event.getIf < sf::Event::MouseButtonReleased >(); mbr && mbr->button == sf::Mouse::Button::Left ) { if( ElementGUI_pressed.get() == this ) { click(); } } } }
|
|
| « 1 » |