c++ - Preventing library internal stuff from beeing visible in .h -


first things first: know thats it's quite probable question based on general missunderstanding, hope can make point clear you.

i know when putting code diffrent files in c++ have create .h (for definitions) , .cpp (for implementations). when writing class-library example have put definitioj of both, private , public members in header. if - reason - want hide private things user?

thanks!

you use pimpl idiom. pimpl stands "pointer implementation". basically, don't store implementation details in class. instead store opaque pointer implementation such:

class myclass { public:      //public functions here private:     class impl; //no definition, opaque     impl* pimpl; }; 

and go on define myclass::impl class in .cpp file only, because function definitions need it.

the pimpl idiom has additional benefit long interface of class not change, changes made implementation not require recompilation of class clients.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -