From d49f1a848440b1ffbaeacdabd1412c3ad1dd6800 Mon Sep 17 00:00:00 2001 From: light-city <455954986@qq.com> Date: Wed, 7 Aug 2019 14:36:00 +0800 Subject: [PATCH] update dir --- README.md | 1 + c_poly/README.md | 7 ++ explicit/README.md | 6 ++ explicit/{explict => explicit} | Bin 9288 -> 9288 bytes explicit/{explict.cpp => explicit.cpp} | 0 friend/README.md | 14 +++ union/README.md | 6 ++ using/README.md | 120 +++++++++++++++++++++++++ using/derived_base | Bin 0 -> 15168 bytes using/derived_base.cpp | 48 ++++++++++ using/using_derived | Bin 0 -> 9320 bytes using/using_derived.cpp | 36 ++++++++ using/using_global | Bin 0 -> 9296 bytes using/using_global.cpp | 45 ++++++++++ using/using_typedef | Bin 0 -> 22024 bytes using/using_typedef.cpp | 34 +++++++ 16 files changed, 317 insertions(+) rename explicit/{explict => explicit} (75%) rename explicit/{explict.cpp => explicit.cpp} (100%) create mode 100644 using/README.md create mode 100755 using/derived_base create mode 100644 using/derived_base.cpp create mode 100755 using/using_derived create mode 100644 using/using_derived.cpp create mode 100755 using/using_global create mode 100644 using/using_global.cpp create mode 100755 using/using_typedef create mode 100644 using/using_typedef.cpp diff --git a/README.md b/README.md index b70efaf..6e8ddf5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ - [x] [c实现c++多态那些事](./c_poly) - [x] [explicit那些事](./explicit) - [x] [friend那些事](./friend) +- [x] [using那些事](./using) 代码运行: 全部在linux下用vim编写,使用gcc/g++调试!全部可正常运行! diff --git a/c_poly/README.md b/c_poly/README.md index 790eebe..ed91220 100644 --- a/c_poly/README.md +++ b/c_poly/README.md @@ -1,4 +1,11 @@ # C实现C++的面向对象特性 + +## 关于作者: + +个人公众号: + +![](../img/wechat.jpg) + ## 1.C++实现案例 C++中的多态:在C++中会维护一张虚函数表,根据赋值兼容规则,我们知道父类的指针或者引用是可以指向子类对象的。 diff --git a/explicit/README.md b/explicit/README.md index 05dda6f..740b7b0 100644 --- a/explicit/README.md +++ b/explicit/README.md @@ -1,5 +1,11 @@ # explicit(显式)关键字那些事 +## 关于作者: + +个人公众号: + +![](../img/wechat.jpg) + - explicit 修饰构造函数时,可以防止隐式转换和复制初始化 - explicit 修饰转换函数时,可以防止隐式转换,但按语境转换除外 diff --git a/explicit/explict b/explicit/explicit similarity index 75% rename from explicit/explict rename to explicit/explicit index 888e363d011400d15fd013a52ce83edebb45c046..ab3a4124b4c8e2fc61e774ca575ca55d4998cb7a 100755 GIT binary patch delta 592 zcmX@%al&Im3zLZN?6@}Vqa0tZWJ3{g$vZ#}69XSZDTf1C*bXAez%w~fM4wS*@ zDr5+p{1IqQI#^bifrBprCIO}^CM$}HOLhZg85zVFB+z6xP7VahP65g)0p0Kg>IQzO z2@57S0%cbLWrcvU4N!ZTpt4&hZxj`0+%@?jkUR+@CAWZ8@-wucx$y2}K{0VjCZI-; zEzh8~@IlStnd~Sg&ZrG0T_+cciL+(_RVqxr$SBO%HhCeCKNZejKlviiq&+~sAd@6R zfItG&3tJ>$L@$1+>Wos@D-{76`natSE7aF>~`{i6_jP WPsrS0W2~CIP`RDSiFxuX894wJuVJMC delta 590 zcmZXPu}eZx6voeeVk(0A^7*beBr>6>2r(Kf6dK&J|3H_Zu_B@&Ffal)IYMsXmL#FP zprWZ39a@A4qJ{!#a4M*wt@Ez82D`(#_uSuizH?4H-A*?On&J7XpB$~!r}X%xe`~UH zdSMm!tcsS`MH2uR1fc9m(#wAL&mATVE}kgSzz5szr2Jm$L-1nGh_e`$49*f*GvZ=V z7V1z@K1v7~{2-q-NrT|_Wq*OZcQ6{_qDYj13E=_Sz*VA1bev}RR5SRM!!hm?tq~n2 znpb@_MbEJr;_M1vDYoq>EUENEVPL{%)J-lJ71~|iR2QG}@nXv4Y+A-;+%UOwos?tP zVL^6)Rm#hM`5AV|>6&s~6OajHl}G<-A>&-!t3D3{+q__c=sQt+n^{*<7P*weH|98Z zIvqr1=O~s)J)(A>7*KEG4bd4=2jKr4bFy~9_M%Snsy0Pl_UU0Xd~0>XU5C|*JPxs4 Nti}$tlmmN_(H|p_U$g)K diff --git a/explicit/explict.cpp b/explicit/explicit.cpp similarity index 100% rename from explicit/explict.cpp rename to explicit/explicit.cpp diff --git a/friend/README.md b/friend/README.md index 768b95c..64ba791 100644 --- a/friend/README.md +++ b/friend/README.md @@ -1,4 +1,11 @@ # 友元函数与友元类 + +## 关于作者: + +个人公众号: + +![](../img/wechat.jpg) + ## 0.概述 友元提供了一种 普通函数或者类成员函数 访问另一个类中的私有或保护成员 的机制。也就是说有两种形式的友元: @@ -11,6 +18,13 @@ 缺点:破坏了类的封装性和数据的透明性。 +总结: +- 能访问私有成员 +- 破坏封装性 +- 友元关系不可传递 +- 友元关系的单向性 +- 友元声明的形式及数量不受限制 + ## 1.友元函数 在类声明的任何区域中声明,而定义则在类的外部。 diff --git a/union/README.md b/union/README.md index 5811fb9..5421d42 100644 --- a/union/README.md +++ b/union/README.md @@ -1,5 +1,11 @@ # UNION那些事 +## 关于作者: + +个人公众号: + +![](../img/wechat.jpg) + 联合(union)是一种节省空间的特殊的类,一个 union 可以有多个数据成员,但是在任意时刻只有一个数据成员可以有值。当某个成员被赋值后其他成员变为未定义状态。联合有如下特点: - 默认访问控制符为 public diff --git a/using/README.md b/using/README.md new file mode 100644 index 0000000..1e50179 --- /dev/null +++ b/using/README.md @@ -0,0 +1,120 @@ +# using那些事 +## 关于作者: + +个人公众号: + +![](../img/wechat.jpg) + +## 基本使用 + +局部与全局using,具体操作与使用见下面案例: + +```c++ +#include +#define isNs1 1 +//#define isGlobal 2 +using namespace std; +void func() +{ + cout<<"::func"< +using namespace std; + +class Base{ + public: + void f(){ cout<<"f()"< V1; +using V2 = vector; +``` +完整代码见:[using_typedef.cpp](using_typedef.cpp) diff --git a/using/derived_base b/using/derived_base new file mode 100755 index 0000000000000000000000000000000000000000..952568af0a1cd97323845d08059ce62a05e48c01 GIT binary patch literal 15168 zcmeHOeQ;FQb-%lkKzuC=mV*MeSuiHpm}Lb*mg6`)eZ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iDqDYtyn!F{H3Y;CjD?8qn0%?&JKIlGP! zI{db8L{}iE%fodAv$@roPf2Dy|)20@`f1~CIw z5KqT0Jn{HB{F?&$e#avo-`IAM{VMst828Qr@jA=xKn_j68Q^W0~qb= zYM?H1hw*x(<0SIscC*?6h*$osyzINZ&W_4{FtckNQYZK@F4~I~`?5dxJ{d%j?*zR5 z=^}gr_kl`#yMoI;o}WKZ57=TlpPT#?|Cy|4e}!BXdD-t9V)-^^6#F7C{XfL=wahm@ z)6lhXmJe|JNS^kP-15(YMl9Uj?EayjKS*Ss9xS?WSOryss5#|jpE1Ppln3T4^8Fz2 z576k8SF;V9oj-iUU(w;lzwMHj{RcnG|IFpE*cE+$>XMi9i{kk<2X{l*r_BGqV0jro z`9Aiu{92B`C~*7#eV4q!-+cx<`l<*rbae-5vUdE$zU-?`u>37F=^Vvv|82C9iy|-k zuVrPnko%j;)gAR7*nGIejO=&G|C71n?Y94)kfl(GyzJ*r+zKL!o8OIp3Lf%F;o7sNIMHl%E zF1n}_xB%^9+sS&%Ivcx97`f4f=FMHF{BXd={Pb`^q2ZwasgwT8`Z)` + +using namespace std; + +class Base1 { + public: + Base1():value(10) {} + virtual ~Base1() {} + void test1() { cout << "Base test1..." << endl; } + protected: // 保护 + int value; +}; +// 默认为私有继承 +class Derived1 : Base1 { + public: + void test2() { cout << "value is " << value << endl; } +}; + +class Base { + public: + Base():value(20) {} + virtual ~Base() {} + void test1() { cout << "Base test1..." << endl; } + protected: //私有 + int value; +}; + +/** + * 子类对父类成员的访问权限跟如何继承没有任何关系, + * “子类可以访问父类的public和protected成员,不可以访问父类的private成员”——这句话对任何一种继承都是成立的。 + * + */ +class Derived : Base { + public: + using Base::value; + void test2() { cout << "value is " << value << endl; } +}; + + +int main() +{ + Derived1 d1; + d1.test2(); + + Derived d; + d.test2(); + return 0; +} diff --git a/using/using_derived b/using/using_derived new file mode 100755 index 0000000000000000000000000000000000000000..641ac8b671a8dd7bbec9bff9af71cb9a96e8fb1a GIT bin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mxT?ZDDI z3M#LjJCAeu0a;AwPkJi-8LiRtKvGqeSI?*Ws8f)<5?JqXsPd})_kvF4Yne~IXR(LN ztM@WUe|qNWEdOQT$R@0=^}M?b`&N|H{+7(iy3{qn6n^&d>bba=%L}5dKp9^v_>i;w zIex+6#Xc=1rLW9Q&VL;Qd;NYc@8|Lr*x$1!RjUq3*q2y4_Q2ffRRQ^A? zyy`#o+?KD zQG0po{RlSvuoPqct8xmS<0!A5YY%gIrKb|0%BehkACPdW{c0b7H_Y(UHyaU3>YXtk3|D|I0w6xk$BN#ZMaF Sx$0lXFGzfqoZFV1_5VK+_sQ1) literal 0 HcmV?d00001 diff --git a/using/using_typedef.cpp b/using/using_typedef.cpp new file mode 100644 index 0000000..5807122 --- /dev/null +++ b/using/using_typedef.cpp @@ -0,0 +1,34 @@ +/** + * @file using_typedef.cpp + * @brief g++ -o using_typedef using_typedef.cpp -std=c++11 + * 取代typedef,使用using来定义别名 + * @author 光城 + * @version v1 + * @date 2019-08-07 + */ + +#include +#include +using namespace std; + +typedef vector V1; +using V2 = vector; + + +int main() +{ + int nums1[] = {1,2,3,4,5,6}; + V1 vec1(nums1,nums1+sizeof(nums1)/sizeof(int)); + int nums2[] = {5,7,6}; + V2 vec2(nums2,nums2+sizeof(nums2)/sizeof(int)); + + for(auto i:vec1) + cout<