Boost logo

Boost Users :

From: Oliver.Kowalke_at_[hidden]
Date: 2005-10-27 08:06:42


>Is there a page somewhere that describes the trick, just out of
interest
>like.

C++ Template Metaprogramming, page 205
Modern C++ Design, somewhere

AFAIK - Barton & Nackmann trick is used for class composition:

template< typename Derived >
struct Add
{
        int add()
        {
                // B & N-trick: access to the Composed class
                D & d = static_cast< Derived & >( * this);

                return d.first() + d.second();
        }
};

struct First
{
        int first()
        { return 1; }
};

struct Second
{
        int second()
        { return 2; }
};

class Composed
: inherit_scattered< vector< First, Second, Add< Composed > > >
{};

void main()
{
        Composed c;

        Std::cout << c.add() << std::endl;
}


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