Re: Why do managed event handlers still use '&" ?
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Tue, 29 Nov 2005 20:02:13 -0600
On Tue, 29 Nov 2005 15:36:42 -0800, "Peter Oliphant"
<poliphant@xxxxxxxxxxxxxxxx> wrote:
>Hi Doug,
>
>That brings up an interesting question. If it is illegal to create a handler
>with unrelated objects (which totally makes sense), why is it required to
>completely qualify the handler's name? That is, why do we have to do:
>
>Click += gcnew EventHandler( this, &MyClass::Handler ) ;
>
>why isn't this just fine:
>
>Click += gcnew EventHandler( this, &Handler ) ;
It could do that, but it would make for a gratuitous incompatibility with
Standard C++. Remember, in Standard C++, there's exactly one way to form a
pointer to member. Also, qualifying the name with MyClass:: tells the
compiler exactly where in the class hierarchy to start looking for the name
"Handler". Normally, this would be the static type of *this, but it could
also be a base class. You might argue that since there's an obvious choice
of default starting point, the qualifier should be optional, but then we're
back to the "gratuitous incompatibility". I do get the feeling you'd like
the C# syntax better, which is, IIRC, something like
EventHandler(this.Handler).
--
Doug Harrison
Visual C++ MVP
.
- References:
- Why do managed event handlers still use '&" ?
- From: Peter Oliphant
- Re: Why do managed event handlers still use '&" ?
- From: Doug Harrison [MVP]
- Re: Why do managed event handlers still use '&" ?
- From: Peter Oliphant
- Why do managed event handlers still use '&" ?
- Prev by Date: Re: Multiple simulataneous forms in a sinlge application
- Next by Date: Re: Multiple simulataneous forms in a sinlge application
- Previous by thread: Re: Why do managed event handlers still use '&" ?
- Next by thread: TRICK: Unique ID'ing
- Index(es):
Relevant Pages
|