dotfiles/fake_home/.vim/templates/skeleton.cpp

47 lines
931 B
C++
Raw Normal View History

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