Boost logo

Boost :

From: axter (boost_at_[hidden])
Date: 2006-01-04 01:04:50


"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
news:<dpf7ec$9kl$1_at_[hidden]>...
> axter wrote:
> >
> >
> > I think the cow_ptr should be used as the default method for
> > creating containers of pointers, and that the current boost pointer
> > containers should be used when memory management is the more
> > important factor for a particular requirement.
>
> Their primary purpose is to facilitate OOP in C++. This domain is
> sufficiently different from the value-based domain that different
> programming idioms apply.
>
>
> > I'm not sure about the ptr_set and ptr_map classes, because I
> > haven't seen any example code usage that would have it work with an
> > abstract type.
>
> Listen, when you said you could get it to work with an abstract type,
> I
> tried it out.
>
> It works fine, but one gets errors if one does not define new_clone()
> for the abstract type:
>
> namespace Foo
> {
> struct abtract_base { ... };
>
> inline new_clone( const abstract_base& r )
> { return r.clone(); }
> }
>
> My guess is that most of the other compile problems go away when you
> define this.
>
> Did you not read
>
> http://www.boost.org/libs/ptr_container/doc/reference.html#the-clonabl
> e-concept

I did read it, and if you read my code, you would see that the new_clone
function is in the shape.h header.

I just tested it again, and again it fails to compile.
I even went through the trouble of taking out all the compiler directives,
and cleaning the code so-as to remove any possible noise, but it still fails
to compile.

One of the compile errors is becaue boost::ptr_map class requires the object
have a default constructor.
After I added a default constructor for test purposes, it still fail to
compile, by giving the following error:
****************************************************************************
*********************************************************
c:\lib\boost_1_33_0\boost\ptr_container\ptr_map_adapter.hpp(171) : error
C2259: 'Shape' : cannot instantiate abstract class
        due to following members:
        'void Shape::draw(void) const' : pure virtual function was not
defined
        m:\__Current\PolymorphicContainersDemo\shape_test.h(12) : see
declaration of 'Shape::draw'
        'std::string Shape::GetShapeName(void) const' : pure virtual
function was not defined
        m:\__Current\PolymorphicContainersDemo\shape_test.h(13) : see
declaration of 'Shape::GetShapeName'
        'Shape *Shape::do_clone(void) const' : pure virtual function was not
defined
        m:\__Current\PolymorphicContainersDemo\shape_test.h(33) : see
declaration of 'Shape::do_clone'
        c:\lib\boost_1_33_0\boost\ptr_container\ptr_map_adapter.hpp(161) :
while compiling class-template member function
'boost::ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMap,CloneAllocat
or>::reference
boost::ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMap,CloneAllocato
r>::insert_lookup(const
boost::ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMap,CloneAllocato
r>::key_type &)'
****************************************************************************
*********************************************************

I get the above error from the following four lines of code:
                boost::ptr_map<int, Shape> mIntToShape;
                int i123 = 123;
                mIntToShape.insert(i123, new Circle("blue"));
                mIntToShape[i123].draw(); //This line is what causes the
error

You can download the shape class from following link:
http://code.axter.com/shape_test.h

Have you tested this code with an abstract type, and if so, can you post the
test code?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk