kleine Frage zum pimple idiom
-
Ich hab gerade den shared_ptr studiert und bin auf dieses "Pimple-Idiom" gestossen, das für mich neu ist. Aber ich kapiere nicht, wieso ein shared_ptr dafür notwendig ist.
Das hab ich gelesen:One common usage of shared_ptr is to implement a handle/body (also called pimpl) idiom which avoids exposing the body (implementation) in the header file.
The shared_ptr_example2_test.cpp sample program includes a header file, shared_ptr_example2.hpp, which uses a shared_ptr<> to an incomplete type to hide the implementation. The instantiation of member functions which require a complete type occurs in the shared_ptr_example2.cpp implementation file. Note that there is no need for an explicit destructor. Unlike ~scoped_ptr, ~shared_ptr does not require that T be a complete type.
Genauso gut könnte ich die Informationen durch T* verberegen, dazu brauch ich keinen smart pointer
bitte um Aufklärung
-
ups, es heisst ja "pimpl"