digitalmars.D - C has nested classes, really?
- James Dunne (2/2) Dec 29 2005 http://www.digitalmars.com/d/comparison.html
- Matthew (5/7) Dec 29 2005 And C++ does have perfectly adequate, albeit indirect, support for neste...
- Walter Bright (27/32) Dec 29 2005 I'd disagree with "perfectly adequate." C++ nested functions cannot acce...
- Matthew (5/37) Dec 29 2005 nested
- John C (4/50) Dec 29 2005 Er, not quite. EnumChildWindows expects a pointer to a static function, ...
- Walter Bright (4/6) Dec 29 2005 Right, which is why the D version in the article is forced to do it that...
http://www.digitalmars.com/d/comparison.html Wow, must've missed something about C a while back! =P
Dec 29 2005
And C++ does have perfectly adequate, albeit indirect, support for nested functions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htm ;-) "James Dunne" <james.jdunne gmail.com> wrote in message news:dp1fmc$ole$1 digitaldaemon.com...http://www.digitalmars.com/d/comparison.html Wow, must've missed something about C a while back! =P
Dec 29 2005
"James Dunne" <james.jdunne gmail.com> wrote"Matthew" <matthew hat.stlsoft.dot.org> wrote in message news:dp1hha$pvh$1 digitaldaemon.com...Wow, must've missed something about C a while back! =PAnd C++ does have perfectly adequate, albeit indirect, support for nested functions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htmI'd disagree with "perfectly adequate." C++ nested functions cannot access local variables in their enclosing functions, necessitating a bunch of extra code to transfer any needed data. In your article, this advantage of D nested functions is not used because you're using a C callback function. If the callback function was a D delegate, the code becomes dramatically simpler: HWND FindFirstChildById(HWND hwndParent, int id) { if(GetDlgCtrlID(hwndParent) == id) { return hwndParent; } else { HWND hwndChild; BOOL FindChildProc(HWND hwnd) { return (GetDlgCtrlID(hwnd) == id) ? (hwndChild = hwnd, false) : true; } EnumChildWindows(hwndParent, &FindChildProc); return hwndChild; } }
Dec 29 2005
"Walter Bright" <newshound digitalmars.com> wrote in message news:dp1jf1$rjn$1 digitaldaemon.com...nested"James Dunne" <james.jdunne gmail.com> wrote"Matthew" <matthew hat.stlsoft.dot.org> wrote in message news:dp1hha$pvh$1 digitaldaemon.com...Wow, must've missed something about C a while back! =PAnd C++ does have perfectly adequate, albeit indirect, support forextrafunctions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htmI'd disagree with "perfectly adequate." C++ nested functions cannot access local variables in their enclosing functions, necessitating a bunch ofcode to transfer any needed data. In your article, this advantage of D nested functions is not used because you're using a C callback function. If the callback function was a D delegate, the code becomes dramatically simpler: HWND FindFirstChildById(HWND hwndParent, int id) { if(GetDlgCtrlID(hwndParent) == id) { return hwndParent; } else { HWND hwndChild; BOOL FindChildProc(HWND hwnd) { return (GetDlgCtrlID(hwnd) == id) ? (hwndChild = hwnd, false) : true; } EnumChildWindows(hwndParent, &FindChildProc); return hwndChild; } }True. I forgot about that aspect. :$
Dec 29 2005
"Matthew" <matthew hat.stlsoft.dot.org> wrote in message news:dp1n8l$unj$1 digitaldaemon.com..."Walter Bright" <newshound digitalmars.com> wrote in message news:dp1jf1$rjn$1 digitaldaemon.com...Er, not quite. EnumChildWindows expects a pointer to a static function, not a delegate.nested"James Dunne" <james.jdunne gmail.com> wrote"Matthew" <matthew hat.stlsoft.dot.org> wrote in message news:dp1hha$pvh$1 digitaldaemon.com...Wow, must've missed something about C a while back! =PAnd C++ does have perfectly adequate, albeit indirect, support forextrafunctions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htmI'd disagree with "perfectly adequate." C++ nested functions cannot access local variables in their enclosing functions, necessitating a bunch ofcode to transfer any needed data. In your article, this advantage of D nested functions is not used because you're using a C callback function. If the callback function was a D delegate, the code becomes dramatically simpler: HWND FindFirstChildById(HWND hwndParent, int id) { if(GetDlgCtrlID(hwndParent) == id) { return hwndParent; } else { HWND hwndChild; BOOL FindChildProc(HWND hwnd) { return (GetDlgCtrlID(hwnd) == id) ? (hwndChild = hwnd, false) : true; } EnumChildWindows(hwndParent, &FindChildProc); return hwndChild; } }True. I forgot about that aspect. :$
Dec 29 2005
"John C" <johnch_atms hotmail.com> wrote in message news:dp1npr$v7k$1 digitaldaemon.com...Er, not quite. EnumChildWindows expects a pointer to a static function, not a delegate.Right, which is why the D version in the article is forced to do it that way. If you're calling a D function, you'd use a delegate.
Dec 29 2005