"Emil Dotchevski"
On Tue, May 31, 2016 at 2:45 PM, Rob Stewart
wrote: On May 31, 2016 5:10:35 PM EDT, Emil Dotchevski
wrote: header:
struct foo { int critical_; }; shared_ptr<foo> create_foo(); inline void use_foo_critical( foo * p ) { ++p->critical_; } void use_foo_not_so_critical( foo * )
Were you leaving encapsulation as an exercise for the reader?
class foo { public: use_critical () { ++critical_; } protected: int critical_; };
Your foo_ can still access critical_.
Right, though my preference is as follows.
//Public interface:
namespace boost { template <class> class shared_ptr; } class foo; boost::shared_ptr<foo> create_foo(); void use_foo_critical( foo * ); void use_foo_not_so_critical( foo * );
//Implementation details:
class foo { foo( foo const & ); foo & operator=( foo const & ); int critical_; friend void use_foo_critical( foo * ); protected: foo(); ~foo(); }; inline void use_foo_critical( foo * p ) { ++p->critical_; }
That doesn't provide inline access to those with access only to the header.