P
Peter Oliphant
I've upgraded my code to VS C++.NET 2005 (Express) using /clr pure. My
question is, why is there an exception to the rule in how pointer syntax is
done in the event handlers?
For example, why is this proper syntax:
button->Click += gcnew EventHandler( this, &MyClass::MouseHandler ) ;
The '&' seems like a hold over from the old syntax, except this is the NEW
syntax (i.e., it never wanted the '&' before 2005 at all). Why was the '&'
added (it's not like anything BUT a pointer would make sense), and why was
the old syntax 'address of' symbol used? That is, before this was done like
this:
button->Click += new EventHandler( this, MyClass::MouseHandler ) ;
That is, no '&'. Thus, it seems the proper transition would be to this
syntax:
button->Click += gcew EventHandler( this, MyClass::MouseHandler ) ;
This means the only reason to add the '&' is if the line immediately above
could somehow be ambiguous, which I don't think it can be. So adding the
superfulous '&' seems odd.
Further, almost humerously, the compile upon seeing the non-'&' form
generates an error that basically says 'you need to add the '&'". Well, if
it knows this, and there is no ambiguity involved, why not accept BOTH
forms? Or dang it, why not provide the ability to click on such an error
message and have an option for IT make the correction? And possibly allow a
MAKE ALL CORRECTIONS button, letting the compiler do some of the work! Its
really a bit irritating when it says 'this is what you did wrong, this is
how its done' without the ability to fix it automatically (and such a method
would not be prone to typos!)...
[==P==]
question is, why is there an exception to the rule in how pointer syntax is
done in the event handlers?
For example, why is this proper syntax:
button->Click += gcnew EventHandler( this, &MyClass::MouseHandler ) ;
The '&' seems like a hold over from the old syntax, except this is the NEW
syntax (i.e., it never wanted the '&' before 2005 at all). Why was the '&'
added (it's not like anything BUT a pointer would make sense), and why was
the old syntax 'address of' symbol used? That is, before this was done like
this:
button->Click += new EventHandler( this, MyClass::MouseHandler ) ;
That is, no '&'. Thus, it seems the proper transition would be to this
syntax:
button->Click += gcew EventHandler( this, MyClass::MouseHandler ) ;
This means the only reason to add the '&' is if the line immediately above
could somehow be ambiguous, which I don't think it can be. So adding the
superfulous '&' seems odd.
Further, almost humerously, the compile upon seeing the non-'&' form
generates an error that basically says 'you need to add the '&'". Well, if
it knows this, and there is no ambiguity involved, why not accept BOTH
forms? Or dang it, why not provide the ability to click on such an error
message and have an option for IT make the correction? And possibly allow a
MAKE ALL CORRECTIONS button, letting the compiler do some of the work! Its
really a bit irritating when it says 'this is what you did wrong, this is
how its done' without the ability to fix it automatically (and such a method
would not be prone to typos!)...
[==P==]