More comprehensive C++ skeleton
With unique_ptr usage, and basic map iteration. Delete old fake_home/vim_templates directory
This commit is contained in:
parent
c283b58a18
commit
5eccbfcbfc
|
@ -1,10 +1,13 @@
|
||||||
// skeleton.cpp
|
// skeleton.cpp
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class Person
|
class Person
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::map<std::string, std::string> attributes {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -13,17 +16,31 @@ class Person
|
||||||
this->name = name;
|
this->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Person* addAttribute(std::string key, std::string value)
|
||||||
|
{
|
||||||
|
this->attributes[key] = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
void greet()
|
void greet()
|
||||||
{
|
{
|
||||||
std::cout << "Hello, my name is " << this->name << "!" << std::endl;
|
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[])
|
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();
|
person->greet();
|
||||||
delete person;
|
// Not necessary with unique_ptr:
|
||||||
|
// delete person;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
CC=gcc
|
|
||||||
CFLAGS=-I.
|
|
||||||
MAIN=hello
|
|
||||||
|
|
||||||
nonnull: $(MAIN).o
|
|
||||||
$(CC) -o $(MAIN) $(MAIN).o
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm ./*.o
|
|
|
@ -1,5 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("Hello, world!\n");
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
cout << "Hello, world!" << endl;
|
|
||||||
}
|
|
|
@ -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>
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
echo "Hello, world!"
|
|
Loading…
Reference in New Issue