Skip to content

Commit 7ae4135

Browse files
authored
tab page, admonition
1 parent 0f57b7e commit 7ae4135

File tree

3 files changed

+101
-66
lines changed

3 files changed

+101
-66
lines changed

docs/c-cpp/basics/pointer_and_ref.md

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,78 @@
44
2. 但是引用需要在声明的时候初始化,而且一旦指向某个对象,不会再改变;
55
3. 对初始化的引用再次赋值,是对引用指向的对象进行赋值,引用本身始终指向最初的对象,它是那个对象的别名。
66

7+
=== "snippet-1"
78

8-
```cpp
9-
#include <iostream>
10-
void swapByPointer(int* a, int* b) {
11-
int temp = *a;
12-
*a = *b;
13-
*b = temp;
14-
}
15-
void swapByReference(int& a, int& b) {
16-
int temp = a;
17-
a = b;
18-
b = temp;
19-
}
20-
int main() {
21-
int x = 5;
22-
int y = 10;
23-
std::cout << "Before swapping: x = " << x << ", y = " << y << std::endl;
24-
// 使用指针交换变量的值
25-
swapByPointer(&x, &y);
26-
std::cout << "After swapping by pointer: x = " << x << ", y = " << y << std::endl;
27-
x = 5;
28-
y = 10;
29-
// 使用引用交换变量的值
30-
swapByReference(x, y);
31-
std::cout << "After swapping by reference: x = " << x << ", y = " << y << std::endl;
32-
return 0;
33-
}
34-
```
9+
```cpp
10+
#include <iostream>
11+
void swapByPointer(int* a, int* b) {
12+
int temp = *a;
13+
*a = *b;
14+
*b = temp;
15+
}
16+
void swapByReference(int& a, int& b) {
17+
int temp = a;
18+
a = b;
19+
b = temp;
20+
}
21+
int main() {
22+
int x = 5;
23+
int y = 10;
24+
std::cout << "Before swapping: x = " << x << ", y = " << y << std::endl;
25+
// 使用指针交换变量的值
26+
swapByPointer(&x, &y);
27+
std::cout << "After swapping by pointer: x = " << x << ", y = " << y << std::endl;
28+
x = 5;
29+
y = 10;
30+
// 使用引用交换变量的值
31+
swapByReference(x, y);
32+
std::cout << "After swapping by reference: x = " << x << ", y = " << y << std::endl;
33+
return 0;
34+
}
35+
```
3536

36-
```cpp
37-
#include <iostream>
38-
using namespace std;
39-
class Parent
40-
{
41-
public:
42-
virtual void v_test() { cout << "Parent::v_test" << endl; }
43-
int a = 0;
44-
};
45-
class Child : public Parent
46-
{
47-
public:
48-
void v_test() override { cout << "Child::v_test" << endl; }
49-
};
50-
int main()
51-
{
52-
Parent parent;
53-
Child child;
54-
parent.a = 1;
55-
child.a = 2;
56-
Parent* p = &child;
57-
Parent& ref_parent = parent;
58-
cout << p->a << endl;
59-
cout << ref_parent.a << endl;
60-
// 对引用指向的对象进行赋值
61-
// 改变的是对象内部的值,a的值变了
62-
ref_parent = child;
63-
cout << ref_parent.a << endl;
64-
p->v_test();
65-
ref_parent.v_test();
66-
return 0;
67-
}
68-
```
37+
=== "snippet-2"
38+
39+
```cpp
40+
#include <iostream>
41+
using namespace std;
42+
class Parent
43+
{
44+
public:
45+
virtual void v_test() { cout << "Parent::v_test" << endl; }
46+
int a = 0;
47+
};
48+
class Child : public Parent
49+
{
50+
public:
51+
void v_test() override { cout << "Child::v_test" << endl; }
52+
};
53+
int main()
54+
{
55+
Parent parent;
56+
Child child;
57+
parent.a = 1;
58+
child.a = 2;
59+
Parent* p = &child;
60+
Parent& ref_parent = parent;
61+
cout << p->a << endl;
62+
cout << ref_parent.a << endl;
63+
// 对引用指向的对象进行赋值
64+
// 改变的是对象内部的值,a的值变了
65+
ref_parent = child;
66+
cout << ref_parent.a << endl;
67+
p->v_test();
68+
ref_parent.v_test();
69+
return 0;
70+
}
71+
```
72+
73+
??? example "输出"
74+
75+
```plaintext
76+
2
77+
1
78+
2
79+
Child::v_test
80+
Parent::v_test
81+
```

docs/c-cpp/design_pattern/template_method.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,35 @@
2424

2525
新建一个WinForm程序,我们可以看到这个Form类被拆成了两部分,一个是用户代码,另一个是设计器生成的代码。最终,它们会被合并成一个XXForm类,而开放给开发者修改的可以看成是一个钩子接口(这里是类包围的多个hook接口)。
2626

27-
!!! Abstract
27+
???+ note
2828

2929
以类为基本单元来看,我觉得继承本身就是一种模板方法模式,或者说模板方法的目的就是多态,而继承也是其实现机制之一。父类的接口是固定的,而子类可以重写父类的某些方法来实现不同的行为。
3030

3131
## UML
3232

33-
![Page-1](../../assets/drawio/c-cpp/template-method.drawio)
34-
![Page-2](../../assets/drawio/c-cpp/template-method.drawio)
35-
![Page-2](../../assets/drawio/c-cpp/template-method.drawio)
33+
=== "UML Diagram"
34+
35+
![Page-1](../../assets/drawio/c-cpp/template-method.drawio)
36+
37+
=== "C# Partial Class"
38+
39+
``` C#
40+
// Customer.Part1.cs
41+
public partial class Customer
42+
{
43+
public string Name { get; set; }
44+
public string Email { get; set; }
45+
}
46+
47+
// Customer.Part2.cs
48+
public partial class Customer
49+
{
50+
public void DisplayCustomerInfo()
51+
{
52+
Console.WriteLine($"Name: {Name}, Email: {Email}");
53+
}
54+
}
55+
```
3656

3757
## Sample
3858

mkdocs.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ repo_url: https://github.com/icecoobe/notes
99
edit_uri: edit/main/docs/
1010

1111
# Copyright
12-
copyright: Copyright &copy; 2025 icecoobe<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
12+
# copyright: Copyright &copy; 2025 icecoobe<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
13+
copyright: Copyright &copy; 2025 icecoobe <a href="https://squidfunk.github.io/mkdocs-material/reference/">Awesome - Material for MkDocs</a>
1314

1415
# Configuration
1516
# ref: https://github.com/krahets/hello-algo/blob/main/mkdocs.yml
@@ -88,7 +89,6 @@ plugins:
8889
# based on the selected theme. Supports classic mkdocs and mkdocs-material.
8990
darkmode: true
9091

91-
9292
extra_css:
9393
- assets/stylesheets/extra.css
9494
extra_javascript:
@@ -130,6 +130,8 @@ markdown_extensions:
130130
- pymdownx.arithmatex:
131131
generic: true
132132
extra:
133+
# remove Made with Material for MkDocs notice
134+
generator: false
133135
social:
134136
- icon: fontawesome/brands/github
135137
link: https://github.com/icecoobe

0 commit comments

Comments
 (0)