From 179751516aa948fb33ae542f298f52ae78f12847 Mon Sep 17 00:00:00 2001 From: Ian Dinwoodie Date: Mon, 29 Apr 2019 20:03:11 -0400 Subject: [PATCH] Added prototype example. --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a0905b..6b75cd6 100644 --- a/README.md +++ b/README.md @@ -635,7 +635,54 @@ scratch and setting it up. #### Programmatic Example -TODO +Let's create a sheep class + +```cpp +class Sheep +{ + public: + Sheep(const std::string& name, const std::string& category) + : name_(name), category_(category) + { + } + + void setName(const std::string name) + { + name_ = name; + } + + std::string getName(void) + { + return name_; + } + + void setCategory(const std::string category) + { + category_ = category; + } + + std::string getCategory(void) + { + return category_; + } + + private: + std::string name_; + std::string category_; +}; +``` +Here is how we can clone this object + +```cpp +Sheep original = Sheep("Molly", "Mountain Sheep"); +std::cout << original.getName() << std::endl; // Output: Molly +std::cout << original.getCategory() << std::endl; // Output: Mountain Sheep + +Sheep clone = original; +clone.setName("Dolly"); +std::cout << clone.getName() << std::endl; // Output: Dolly +std::cout << clone.getCategory() << std::endl; // Output: Mountain Sheep +``` #### When To Use