2024-01-20 19:19:02 -05:00
|
|
|
// skeleton.cpp
|
|
|
|
|
2024-01-20 17:08:20 -05:00
|
|
|
#include <iostream>
|
2024-01-22 20:34:41 -05:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2024-01-20 17:08:20 -05:00
|
|
|
|
|
|
|
class Person
|
|
|
|
{
|
|
|
|
std::string name;
|
2024-01-22 20:34:41 -05:00
|
|
|
std::map<std::string, std::string> attributes {};
|
2024-01-20 17:08:20 -05:00
|
|
|
|
2024-01-22 20:34:41 -05:00
|
|
|
public:
|
2024-01-20 17:08:20 -05:00
|
|
|
|
|
|
|
Person(std::string name)
|
|
|
|
{
|
|
|
|
this->name = name;
|
|
|
|
}
|
|
|
|
|
2024-01-22 20:34:41 -05:00
|
|
|
Person* addAttribute(std::string key, std::string value)
|
|
|
|
{
|
|
|
|
this->attributes[key] = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2024-01-20 17:08:20 -05:00
|
|
|
void greet()
|
|
|
|
{
|
|
|
|
std::cout << "Hello, my name is " << this->name << "!" << std::endl;
|
2024-01-22 20:34:41 -05:00
|
|
|
for (auto& kv : this->attributes) {
|
|
|
|
std::cout << " My " << kv.first << " is " << kv.second << "." << std::endl;
|
|
|
|
}
|
2024-01-20 17:08:20 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2024-01-22 20:34:41 -05:00
|
|
|
auto person = std::unique_ptr<Person>((new Person("Madison"))
|
|
|
|
->addAttribute("best friend", "Bob")
|
|
|
|
->addAttribute("favorite color", "pink")
|
|
|
|
);
|
|
|
|
|
2024-01-20 17:08:20 -05:00
|
|
|
person->greet();
|
2024-06-24 12:24:19 -04:00
|
|
|
|
2024-01-22 20:34:41 -05:00
|
|
|
// Not necessary with unique_ptr:
|
|
|
|
// delete person;
|
2024-01-20 17:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|