Boost logo

Boost :

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

"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
> 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
> 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
        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
        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
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

You can download the shape class from following link:

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

Boost list run by bdawes at, gregod at, cpdaniel at, john at