|
Boost Users : |
Subject: Re: [Boost-users] [corrected]How to delay the initialisation of a member in a C++ base class until the ctor of derived class is executed?
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-03-25 05:16:36
should work, but don't forget to derive 'derived' from base:
class derived : base
{...}
On Wed, Mar 25, 2009 at 10:13 AM, Alex MDC <alex.mdc_at_[hidden]> wrote:
> Is there any C++ design pattern could achieve it? Thanks
>
>
> Since you're passing the size into the derived constructor, why don't you
> just pass it through to the base constructor?
>
> class base
> {
> public:
> base(size_t array_size):size(array_size)
> {
> p_array.reset(new unsigned char[size]);
> }
> private:
> size_t size;
> boost::shared_array<unsigned char> p_array;
> };
>
> class derived
> {
> public:
> derived(size_t array_size):base(array_size)
> {
> }
> };
>
>
> Will that work for you?
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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