From c97a759dcc080705c956c87fce076709ca66a0c8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 1 Sep 2012 11:16:00 +0200 Subject: Add 'access' and 'pimpl' examples These illustrate the use of accessor/modifier functions and expressions as well as virtual data members. --- pimpl/person.cxx | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 pimpl/person.cxx (limited to 'pimpl/person.cxx') diff --git a/pimpl/person.cxx b/pimpl/person.cxx new file mode 100644 index 0000000..6922afc --- /dev/null +++ b/pimpl/person.cxx @@ -0,0 +1,71 @@ +// file : pimpl/person.cxx +// copyright : not copyrighted - public domain + +#include "person.hxx" + +using namespace std; + +struct person::impl +{ + impl () {} + impl (const string& e, const string& n, unsigned short a) + : email (e), name (n), age (a) {} + + string email; + string name; + unsigned short age; +}; + +person:: +~person () +{ + delete pimpl_; +} + +person:: +person () + : pimpl_ (new impl) +{ +} + +person:: +person (const string& e, const string& n, unsigned short a) + : pimpl_ (new impl (e, n, a)) +{ +} + +const string& person:: +email () const +{ + return pimpl_->email; +} + +void person:: +email (const string& e) +{ + pimpl_->email = e; +} + +const string& person:: +name () const +{ + return pimpl_->name; +} + +void person:: +name (const string& n) +{ + pimpl_->name = n; +} + +unsigned short person:: +age () const +{ + return pimpl_->age; +} + +void person:: +age (unsigned short a) const +{ + pimpl_->age = a; +} -- cgit v1.1