From 5eccbfcbfcf1695e709efafa9f91aa1111c2ad6e Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 22 Jan 2024 20:34:41 -0500 Subject: [PATCH] More comprehensive C++ skeleton With unique_ptr usage, and basic map iteration. Delete old fake_home/vim_templates directory --- fake_home/.vim/templates/skeleton.cpp | 23 ++++++++++++++++++++--- fake_home/vim_templates/makefile | 9 --------- fake_home/vim_templates/skeleton.c | 5 ----- fake_home/vim_templates/skeleton.cpp | 7 ------- fake_home/vim_templates/skeleton.html | 23 ----------------------- fake_home/vim_templates/skeleton.sh | 3 --- 6 files changed, 20 insertions(+), 50 deletions(-) delete mode 100644 fake_home/vim_templates/makefile delete mode 100644 fake_home/vim_templates/skeleton.c delete mode 100644 fake_home/vim_templates/skeleton.cpp delete mode 100644 fake_home/vim_templates/skeleton.html delete mode 100755 fake_home/vim_templates/skeleton.sh diff --git a/fake_home/.vim/templates/skeleton.cpp b/fake_home/.vim/templates/skeleton.cpp index d7ae4ec..b579fa6 100644 --- a/fake_home/.vim/templates/skeleton.cpp +++ b/fake_home/.vim/templates/skeleton.cpp @@ -1,29 +1,46 @@ // skeleton.cpp #include +#include +#include class Person { std::string name; + std::map attributes {}; - public: + 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 = new Person("Madison"); + auto person = std::unique_ptr((new Person("Madison")) + ->addAttribute("best friend", "Bob") + ->addAttribute("favorite color", "pink") + ); + person->greet(); - delete person; + // Not necessary with unique_ptr: + // delete person; return 0; } diff --git a/fake_home/vim_templates/makefile b/fake_home/vim_templates/makefile deleted file mode 100644 index 91b50c9..0000000 --- a/fake_home/vim_templates/makefile +++ /dev/null @@ -1,9 +0,0 @@ -CC=gcc -CFLAGS=-I. -MAIN=hello - -nonnull: $(MAIN).o - $(CC) -o $(MAIN) $(MAIN).o - -clean: - rm ./*.o diff --git a/fake_home/vim_templates/skeleton.c b/fake_home/vim_templates/skeleton.c deleted file mode 100644 index 9b216a5..0000000 --- a/fake_home/vim_templates/skeleton.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int main() { - printf("Hello, world!\n"); -} diff --git a/fake_home/vim_templates/skeleton.cpp b/fake_home/vim_templates/skeleton.cpp deleted file mode 100644 index fce833d..0000000 --- a/fake_home/vim_templates/skeleton.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -using namespace std; - -int main() { - cout << "Hello, world!" << endl; -} diff --git a/fake_home/vim_templates/skeleton.html b/fake_home/vim_templates/skeleton.html deleted file mode 100644 index bbe7e61..0000000 --- a/fake_home/vim_templates/skeleton.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - Wow, the title of the new website - - - - - - - - - - - - - -

Hello, world!

-

This is the beginning of a beautiful new website.

- - diff --git a/fake_home/vim_templates/skeleton.sh b/fake_home/vim_templates/skeleton.sh deleted file mode 100755 index 9f3f770..0000000 --- a/fake_home/vim_templates/skeleton.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -echo "Hello, world!"