Boost logo

Boost Users :

From: me22 (me22.ca_at_[hidden])
Date: 2006-08-13 18:11:41


On 8/13/06, Scott Amort <jsamort_at_[hidden]> wrote:
> But now, with shared_ptr, I cannot assign or evaluate to 0. I
> understand that the default ErrorWriterPtr constructor and
> ErrorWriterPtr.reset() will provide me with an empty pointer that I can
> check.
>
Instead of
> if (writer_.get() == 0) { /* create default error writer */ }
Why not just use
if ( !writer_ ) { /* create default error writer */ }
instead? This would work with ordinary pointers too.

> What is the equivalent to:
>
> Parser testParser(0);
>
Parser testParser( ErrorWriterPtr() ); // would work

I'd be tempted instead to replace the constructor definition with
Parser(ErrorWriterPtr writer = ErrorWritePtr())
  : writer_(writer)
  {
  }
however, to be able to just say
Parser testParser;
if you don't want to specify the writer.

~ Scott McMurray


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