aboutsummaryrefslogtreecommitdiff
path: root/pimpl/person.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-09-01 11:16:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-09-01 11:16:00 +0200
commitc97a759dcc080705c956c87fce076709ca66a0c8 (patch)
tree0f11125e3137cef9fc11d669f8addc2955df0460 /pimpl/person.cxx
parent55268128a30a56bfd42a4ffb382ad3a5179a739f (diff)
Add 'access' and 'pimpl' examples
These illustrate the use of accessor/modifier functions and expressions as well as virtual data members.
Diffstat (limited to 'pimpl/person.cxx')
-rw-r--r--pimpl/person.cxx71
1 files changed, 71 insertions, 0 deletions
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;
+}