Skip to content

Commit

Permalink
add 06
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Dec 13, 2021
1 parent 172fd3c commit f377611
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 02/03a/0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

Pig()
{
m_name = "佩奇";
m_weight = 80;
}
};

int main() {
Pig pig;

std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;

return 0;
}
19 changes: 19 additions & 0 deletions 02/03a/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

Pig() : m_name("佩奇"), m_weight(80)
{}
};

int main() {
Pig pig;

std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;

return 0;
}
19 changes: 19 additions & 0 deletions 02/03a/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

Pig(std::string name, int weight) : m_name(name), m_weight(weight)
{}
};

int main() {
Pig pig("佩奇", 80);

std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;

return 0;
}
21 changes: 21 additions & 0 deletions 02/03a/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

Pig(int weight)
: m_name("一只重达" + std::to_string(weight) + "kg的猪")
, m_weight(weight)
{}
};

int main() {
Pig pig(80);

std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;

return 0;
}
21 changes: 21 additions & 0 deletions 02/03a/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

Pig(int weight)
: m_name("一只重达" + std::to_string(weight) + "kg的猪")
, m_weight(weight)
{}
};

int main() {
Pig pig = 80;

std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;

return 0;
}
22 changes: 22 additions & 0 deletions 02/03a/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

explicit Pig(int weight)
: m_name("一只重达" + std::to_string(weight) + "kg的猪")
, m_weight(weight)
{}
};

int main() {
// Pig pig = 80; // 编译错误
Pig pig(80); // 编译通过

std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;

return 0;
}
24 changes: 24 additions & 0 deletions 02/03a/6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <string>

struct Pig {
std::string m_name;
int m_weight;

explicit Pig(int weight)
: m_name("一只重达" + std::to_string(weight) + "kg的猪")
, m_weight(weight)
{}
};

void show(Pig pig) {
std::cout << "name: " << pig.m_name << std::endl;
std::cout << "weight: " << pig.m_weight << std::endl;
}

int main() {
// show(80); // 编译错误
show(Pig(80)); // 编译通过

return 0;
}
5 changes: 5 additions & 0 deletions 02/03a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)
project(hellocpp LANGUAGES CXX)

add_executable(cpptest 6.cpp)
5 changes: 5 additions & 0 deletions 02/03a/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set -e

cmake -B build
cmake --build build
build/cpptest
Binary file modified 02/slides.pptx
Binary file not shown.
Binary file added 03/slides.pptx
Binary file not shown.

0 comments on commit f377611

Please sign in to comment.