新增const函数参数

This commit is contained in:
Hachi 2022-06-16 00:59:10 +08:00
commit 5603f241d6
6 changed files with 338 additions and 0 deletions

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.suggest.snippetsPreventQuickSuggestions": false,
"aiXcoder.showTrayIcon": true
}

244
0001-const.patch Normal file
View File

@ -0,0 +1,244 @@
From 6ca32cbbacd425a37acba74787c6199dbdc54783 Mon Sep 17 00:00:00 2001
From: Hachi <zzy_ahut@163.com>
Date: Thu, 16 Jun 2022 00:52:47 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Econst=E5=87=BD=E6=95=B0?=
=?UTF-8?q?=E5=8F=82=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.vscode/settings.json | 4 ++
.../const/funciton_const/condition4/Test.cpp | 29 +++++++++++++
.../const/funciton_const/condition4/Test.h | 20 +++++++++
.../const/funciton_const/condition4/a.out | Bin 0 -> 18288 bytes
.../const/funciton_const/condition4/main.cpp | 41 ++++++++++++++++++
5 files changed, 94 insertions(+)
create mode 100644 .vscode/settings.json
create mode 100644 basic_content/const/funciton_const/condition4/Test.cpp
create mode 100644 basic_content/const/funciton_const/condition4/Test.h
create mode 100755 basic_content/const/funciton_const/condition4/a.out
create mode 100644 basic_content/const/funciton_const/condition4/main.cpp
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..3986f4a
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,4 @@
+{
+ "editor.suggest.snippetsPreventQuickSuggestions": false,
+ "aiXcoder.showTrayIcon": true
+}
\ No newline at end of file
diff --git a/basic_content/const/funciton_const/condition4/Test.cpp b/basic_content/const/funciton_const/condition4/Test.cpp
new file mode 100644
index 0000000..c1a0e5c
--- /dev/null
+++ b/basic_content/const/funciton_const/condition4/Test.cpp
@@ -0,0 +1,29 @@
+#include "Test.h"
+#include <iostream>
+using namespace std;
+
+Test::Test()
+{
+ cout<<"无参构造"<<endl;
+}
+
+Test::Test(int a)
+{
+ cout<<"类型转换构造器 有参构造"<<endl;
+}
+
+Test::Test(const Test &t)
+{
+ cout<<"拷贝构造"<<endl;
+}
+
+Test::~Test()
+{
+ cout<<"析构函数"<<endl;
+}
+
+void Test::fun() const
+{
+ a = 1; //mutable修饰的成员变量可以被修改
+ //b = 2; //非mutable修饰的变量禁止被修改
+}
diff --git a/basic_content/const/funciton_const/condition4/Test.h b/basic_content/const/funciton_const/condition4/Test.h
new file mode 100644
index 0000000..799cea8
--- /dev/null
+++ b/basic_content/const/funciton_const/condition4/Test.h
@@ -0,0 +1,20 @@
+#ifndef TEST_H
+#define TEST_H
+
+class Test
+{
+public:
+ Test();
+ //类型转换构造函数(有参构造) 用于隐式转换
+ Test(int a);
+ //拷贝构造函数 用于显示转换
+ Test(const Test& t);
+
+ void fun() const;
+
+ ~Test();
+ mutable int a;
+ int b;
+
+};
+#endif // TEST_H
diff --git a/basic_content/const/funciton_const/condition4/a.out b/basic_content/const/funciton_const/condition4/a.out
new file mode 100755
index 0000000000000000000000000000000000000000..a4eca8186ba733790bcc6632fa9719301888fd73
GIT binary patch
literal 18288
zcmeHP4{#LMd4JLgBmNzNf+It0&e%9$%pnPh2wa5|(!r_-tVklpV7wf6Cv>)?Q||Ua
zWP(eg*vS<umNV`^UE)B;iJ6I;kWMmjY#f8Jja}C*ZkvSGNlMdzh3gQk*bV;2_4mE^
zzP-KG9gRJm=}hMyv-;lqegEG3_U+rfxBKy@!PZr!B_)E3M|?_9%QsCS0nO-Np(`K(
zQ7@+8uTRVoSD;-cF~tuk0<J2jN^@zs#yy~<S4ovT^y3N^Ou2_dNv}|OVS?f?6&0#Y
zdgG|7+in^iujH6A-}dKIeBq+E>dr8A>QQWrMM}?T$fYNBTq<}lx?cp7Uboik)_P1U
zSWi=qCz+w6UdPi-ec(~?$-hFl^)_fdH*MDPOvwk8jx$!|qxfsndZ&HTjBwLO6fBss
zzfVJt;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
z+IwPs-fv(!S4(pLS&r%5;L~0fw|QTJ>29r0{il9%|1~UzP@$NzKJQ;JZPOiQ|E$mB
z->dakYJ<FA$MlfKNuQqW-1-NBkqfquM=w=0rTOhF?(@GNOsBq2>oMK!R7TxpUOej3
zKcEGevOJsNHq*l{ecp#*+RuubvL4ePx%ByW2-7+{Fv<YyvDv3x`n<2hbP5Y<>W<%Y
zTA$Cq@M%F!f2o^H`22DEWmG8stbf|4I7}Z=P5ZCg|Eu6Q^?5&u>EmozTX6e7<I?AS
zC#L%G-u6$voaOgu&>oInw(R{W{{JC(p0f`7XX=5$sSbVK$J(+;X|P-&{i)EWQ_TK(
zzl;CB5B~o>==!C?_IMtA8yJm=^?6@xK>v{a3Mn}X>ocW&8>hYqXyGbF3yq&mUIS&a
z#r^{Ut;hOg+))CKI#sXJ{<XNxt<=Cm8&MTD=cKMFA_WbtU!`9R(EEUT9QL@CIr-jz
h`>r8L29~MTORfpaep!~b4f5$X=^xxTxfEPY@!#orU!nj2
literal 0
HcmV?d00001
diff --git a/basic_content/const/funciton_const/condition4/main.cpp b/basic_content/const/funciton_const/condition4/main.cpp
new file mode 100644
index 0000000..ae22eeb
--- /dev/null
+++ b/basic_content/const/funciton_const/condition4/main.cpp
@@ -0,0 +1,41 @@
+#include <iostream>
+#include "Test.h"
+using namespace std;
+
+
+void fun(const Test& t){
+ t.a = 10;
+}
+
+void fun2(const Test& t){
+ t.a = 10;
+}
+
+void fun3(const Test& t){
+ t.a = 10;
+}
+int main()
+{
+ Test t_m;
+ t_m.a = 2;
+
+ cout<<"==================================="<<endl;
+
+ cout<<"调用fun前:"<<t_m.a<<endl;//2
+ fun(2);//隐式转换 隐式类型转换调用类型转换构造函数 发生类型转换const引用再函数中生产临时对象
+ cout<<"调用fun后:"<<t_m.a<<endl;//2
+
+ cout<<"==================================="<<endl;
+
+ cout<<"调用fun2前:"<<t_m.a<<endl;//2
+ fun2(Test(t_m));//显示转换 显式转换调用拷贝构造函数 发生类型转换const引用再函数中生产临时对象
+ cout<<"调用fun2后:"<<t_m.a<<endl;//2
+
+ cout<<"==================================="<<endl;
+
+ cout<<"调用fun3前:"<<t_m.a<<endl;//2
+ fun3(t_m);//没有发生类型转换 不产生临时变量
+ cout<<"调用fun3后:"<<t_m.a<<endl;//10
+
+ return 0;
+}
--
2.25.1

View File

@ -0,0 +1,29 @@
#include "Test.h"
#include <iostream>
using namespace std;
Test::Test()
{
cout<<"无参构造"<<endl;
}
Test::Test(int a)
{
cout<<"类型转换构造器 有参构造"<<endl;
}
Test::Test(const Test &t)
{
cout<<"拷贝构造"<<endl;
}
Test::~Test()
{
cout<<"析构函数"<<endl;
}
void Test::fun() const
{
a = 1; //mutable修饰的成员变量可以被修改
//b = 2; //非mutable修饰的变量禁止被修改
}

View File

@ -0,0 +1,20 @@
#ifndef TEST_H
#define TEST_H
class Test
{
public:
Test();
//类型转换构造函数(有参构造) 用于隐式转换
Test(int a);
//拷贝构造函数 用于显示转换
Test(const Test& t);
void fun() const;
~Test();
mutable int a;
int b;
};
#endif // TEST_H

Binary file not shown.

View File

@ -0,0 +1,41 @@
#include <iostream>
#include "Test.h"
using namespace std;
void fun(const Test& t){
t.a = 10;
}
void fun2(const Test& t){
t.a = 10;
}
void fun3(const Test& t){
t.a = 10;
}
int main()
{
Test t_m;
t_m.a = 2;
cout<<"==================================="<<endl;
cout<<"调用fun前:"<<t_m.a<<endl;//2
fun(2);//隐式转换 隐式类型转换调用类型转换构造函数 发生类型转换const引用再函数中生产临时对象
cout<<"调用fun后:"<<t_m.a<<endl;//2
cout<<"==================================="<<endl;
cout<<"调用fun2前:"<<t_m.a<<endl;//2
fun2(Test(t_m));//显示转换 显式转换调用拷贝构造函数 发生类型转换const引用再函数中生产临时对象
cout<<"调用fun2后:"<<t_m.a<<endl;//2
cout<<"==================================="<<endl;
cout<<"调用fun3前:"<<t_m.a<<endl;//2
fun3(t_m);//没有发生类型转换 不产生临时变量
cout<<"调用fun3后:"<<t_m.a<<endl;//10
return 0;
}