Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

ptr_vector is copy constructible and copy assignable. How can it deep copy the underlying objects when it doesn't know their concrete types?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
476 views
Welcome To Ask or Share your Answers For Others

1 Answer

The boost::ptr_vector container has an optional template parameter, CloneAllocator, that defines the cloning policy. The default allocator is the heap_clone_allocator, which simply invokes the copy constructor to clone an object.

The Clone Allocator is used as a way to add a layer of indirection around the cloning. For example, it allows you to provide a custom allocator that correctly handles cloning of a noncopyable type.

You can find more information in the Boost Pointer Containers Library documentation, which explains the Clonable and Clone Allocator concepts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...