Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #79323

Re: std::bind with member functions and C++20

From MrSpook_1xajf_a1kl@f5mda.co.uk
Newsgroups comp.lang.c++
Subject Re: std::bind with member functions and C++20
Date 2021-04-27 07:37 +0000
Organization Aioe.org NNTP Server
Message-ID <s68f01$13bo$1@gioia.aioe.org> (permalink)
References (6 earlier) <s5sb20$1onq$1@gioia.aioe.org> <s5u2ri$1eti$1@gioia.aioe.org> <s5v29s$t5k$1@gioia.aioe.org> <s6418a$1266$1@gioia.aioe.org> <s67m7v$4ft$1@gioia.aioe.org>

Show all headers | View raw


On Mon, 26 Apr 2021 21:35:13 -0300
Cholo Lennon <chololennon@hotmail.com> wrote:
>On 4/25/21 12:18 PM, MrSpook_Xh_gU9dm@pdj82ouz7mi_c.gov.uk wrote:
>> On Fri, 23 Apr 2021 15:05:48 -0300
>> Cholo Lennon <chololennon@hotmail.com> wrote:
>>> Why obfuscated? why "clever"? on the contrary, this way of using events
>>> and callback is very common. Also, it's very simple and more flexible
>>> than callbacks based on virtual functions, here is a small contrived
>>> example:
>> 
>> I'm confused why you think the 2nd example is clearer or neater, requiring
>> as it does a 2nd class instead of handling everything in 1. But everyone has
>a
>> prefered style I suppose, its just a matter of taste.
>> 
>
>I am just showing different use cases, I am not saying than the 1st 
>example is better than the 2nd one (or vice versa), but the latter is 
>very common, for example, in GUI applications... your Window/Dialog 
>class handles the events from the contained widgets. You can use free 
>functions as event handlers, but member functions has the context of the 
>parent class (of course, std::bind is very powerful so you can add the 
>context to your free functions if you want), i.e:

Perhaps I'm just biased, but IMO if the answer is using std::bind() to link
an object method to a function pointer then you're asking the wrong 
question. In simple code I'm sure it wouldn't be an issue, but in a complex
project that may be hacked about by dozens of people over the years the chances
the object may be deleted leaving a dangling function pointer elsewhere in
the code grows much higher.

>Usually, the initWidget member function (initializeComponent/jbInit in 
>C#/Java) are managed by the GUI editor/IDE, so the event connection (as 
>well as the widget configuration) is automatic. In the old days of MFC, 
>a message map built with macros was the initWidget equivalence. The map 
>was managed by the Class Wizard (*) tool.

A much safer and simpler method on an event is simply to call a callback
with the widget id. Event driven GUI code isn't speed critical so if safety 
and simplicity costs a few extra cpu cycles then its a trade worth making.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-19 11:23 +0200
  Re: std::bind with member functions and C++20 MrSpook_78@xvdv0t9masednkplrcjyxfsl.tv - 2021-04-19 09:32 +0000
    Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-19 13:04 +0200
      Re: std::bind with member functions and C++20 Öö Tiib <ootiib@hot.ee> - 2021-04-21 23:59 -0700
        Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 10:06 +0200
          Re: std::bind with member functions and C++20 Melzzzzz <Melzzzzz@zzzzz.com> - 2021-04-22 08:14 +0000
            Re: std::bind with member functions and C++20 "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 01:20 -0700
            Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 11:32 +0200
      Re: std::bind with member functions and C++20 Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-04-22 07:12 -0700
        Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 17:50 +0200
          Re: std::bind with member functions and C++20 MrSpook_tm0@i9d.com - 2021-04-22 16:25 +0000
            Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 19:02 +0200
              Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 19:25 +0200
            Re: std::bind with member functions and C++20 Cholo Lennon <chololennon@hotmail.com> - 2021-04-22 14:16 -0300
              Re: std::bind with member functions and C++20 MrSpook_wqqeppl@_nb0l03nl53p.tv - 2021-04-23 09:09 +0000
                Re: std::bind with member functions and C++20 Cholo Lennon <chololennon@hotmail.com> - 2021-04-23 15:05 -0300
                Re: std::bind with member functions and C++20 Cholo Lennon <chololennon@hotmail.com> - 2021-04-23 15:47 -0300
                Re: std::bind with member functions and C++20 MrSpook_Xh_gU9dm@pdj82ouz7mi_c.gov.uk - 2021-04-25 15:18 +0000
                Re: std::bind with member functions and C++20 Öö Tiib <ootiib@hot.ee> - 2021-04-25 10:07 -0700
                Re: std::bind with member functions and C++20 MrSpook_2p4eH@0kd0c4bkwzno.biz - 2021-04-26 07:40 +0000
                Re: std::bind with member functions and C++20 Cholo Lennon <chololennon@hotmail.com> - 2021-04-26 21:35 -0300
                Re: std::bind with member functions and C++20 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-27 05:32 +0200
                Re: std::bind with member functions and C++20 Cholo Lennon <chololennon@hotmail.com> - 2021-04-27 00:46 -0300
                Re: std::bind with member functions and C++20 MrSpook_1xajf_a1kl@f5mda.co.uk - 2021-04-27 07:37 +0000
            Re: std::bind with member functions and C++20 Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-04-22 10:35 -0700
  Re: std::bind with member functions and C++20 Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-04-22 07:11 -0700

csiph-web