|
Boost Users : |
From: John Femiani (JOHN.FEMIANI_at_[hidden])
Date: 2008-07-16 13:33:39
>
> 1) I found code fragment like this, esp. in macro definitions:
>
> do { \
> \
> // ... \
> } while(0)
>
> Why is the do/while clause needed here?
Probably so the statements inside the do...while are in their own block,
with its own scope. If simple curly braces were used, then sometimes it
would break 'if' statements in a weird way, so using do {} while(0) is
more robust.
Example:
#define FOO { ... }
if (cond)
FOO; //<--- breaks
else
FOO;
>
> 2) I found large amount of code like this in a class implementation:
>
> AClass::func()
> {
> this->func1();
> }
>
> Why is 'this->' needed?
>
Probably because the class is a template with a template base class, so
explicitly using this-> is one way to make sure that g++ recognizes
func1 as an inheritted member function. Another possiblity is that
typeing '->' triggers the autocomplete function in some editors, so
typing 'this->' provides them with a convenient way to recall & type the
correct function name within the scope of 'this'.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net