Boost logo

Boost Users :

From: boost_www (boost_www_at_[hidden])
Date: 2008-07-16 21:49:48


Hello John

Also many thanks to you for your explanation.

B/Rgds
Max

----- Original Message ----
From: John Femiani
To: boost-users_at_[hidden]
Sent: 2008-07-17 01:36:03
Subject: Re: [Boost-users] Several questions on C++

>

>
> 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 mailing list
Boost-users_at_[hidden]


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