More comprehensive C++ skeleton

With unique_ptr usage, and basic map iteration.
Delete old fake_home/vim_templates directory
This commit is contained in:
Sage Vaillancourt 2024-01-22 20:34:41 -05:00
parent c283b58a18
commit 5eccbfcbfc
6 changed files with 20 additions and 50 deletions

View File

@ -1,10 +1,13 @@
// skeleton.cpp
#include <iostream>
#include <map>
#include <memory>
class Person
{
std::string name;
std::map<std::string, std::string> attributes {};
public:
@ -13,17 +16,31 @@ class Person
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<Person>((new Person("Madison"))
->addAttribute("best friend", "Bob")
->addAttribute("favorite color", "pink")
);
person->greet();
delete person;
// Not necessary with unique_ptr:
// delete person;
return 0;
}

View File

@ -1,9 +0,0 @@
CC=gcc
CFLAGS=-I.
MAIN=hello
nonnull: $(MAIN).o
$(CC) -o $(MAIN) $(MAIN).o
clean:
rm ./*.o

View File

@ -1,5 +0,0 @@
#include <stdio.h>
int main() {
printf("Hello, world!\n");
}

View File

@ -1,7 +0,0 @@
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
}

View File

@ -1,23 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<title>Wow, the title of the new website</title>
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="manifest" href="site.webmanifest">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#242627">
<meta name="msapplication-TileColor" content="#224679">
<meta name="theme-color" content="#ffffff">
<meta name="description" content="This should be a lovely new description">
</head>
<body>
<h1>Hello, world!</h1>
<p>This is the beginning of a beautiful new website.</p>
</body>
</html>

View File

@ -1,3 +0,0 @@
#!/bin/bash
echo "Hello, world!"