knowledge-database (beta)

Current group: comp.soft-sys.ace

[ace-users] C++NPv2 Streams issue - Possible explanation/Book Errata

[ace-users] C++NPv2 Streams issue - Possible explanation/Book Errata  
David Hawkins
From:David Hawkins
Subject:[ace-users] C++NPv2 Streams issue - Possible explanation/Book Errata
Date:22 Jan 2005 03:19:58 -0600

> >From display_logfile.cpp:
>
> template
> class Logrec_Module : public ACE_Module
> {
> public:
> Logrec_Module (const ACE_TCHAR *name)
> : ACE_Module
> (name,
> &task_, // Initialize writer-side task.
> 0, // Ignore reader-side task.
> 0,
> ACE_Module::M_DELETE_READER) {}
> private:
> TASK task_;
> };
>
> The task_ member of the module is passed as an
> argument to the base-class constructor of the
> module. However, the constructor of the task_
> object has not been called yet, so task_ is
> probably bogus.
>
> ......
>
> If this is the correct solution to the problem ...

This is indeed the problem.

A search on "constructor initialization list gotchas" yields

http://www.awprofessional.com/content/downloads/dewhurst67.pdf

and

Effective C++, 2nd Ed, Scott Meyers,

Item 13 "List members in an initialization list in
the order in which they are declared"

and

Exceptional C++, Herb Sutter,

"Item 47: Control flow"

also describe the issue.

Since the base class object is constructed before the inherited
object, the inherited object member task_ has yet to exist.

Hmm, when we pass the address of task_ to the base constructor,
what are we really passing? How come this doesn't segv then?
Perhaps it does on other compilers.

Dave
   

Copyright © 2006 knowledge-database   -   All rights reserved