c++ - Compilation dependencies between files and the pimple idiom -


i'm reading effective c++ scott meyers, , have question item 31, "minimize compilation dependencies between files."

in example shows pimple idiom:

#include <string> // standard lib shouldn't forward-declared  #include <memory>  class personimpl;  // forward decl of person impl.class  class date;        // forward decls of classes used in person interface class address;  class person { public:     person(const std::string& name, const date& birthday, const address& addr);     std:string name() const;     std:string birthdate() const;     std:string address() const;     ... private:     std::tr1::shared_ptr<personimpl> pimpl; }; 

then says this:

avoid using objects when object references , pointers do. may define references , pointers type declaration type. defining objects of type necessitates presence of type's definition.

is there ever time when can't use references or pointers? couldn't use pimple idiom all classes design?

some context require complete types. e.g: when you'd store object value in vector:

std::vector<person> persons; // person must complete 

you can't use reference here, , suppose you'd avoid having empty persons (= nullptr).

please note, far can tell, nowadays pimpl idiom avoided because of added complexity, performance , storage penalty.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -