C++???м?С???????к???м?е?????
???????????? ???????[ 2016/12/26 11:31:43 ] ??????????????????? C++
??????c++???п????У???????????????????????public??protected??private????????????????????????????????????????????????????struct????????????public??У?class????????????private??С????Java?к???????Java??????public??У???????й??м?С?
????1.???public???????????????????????????public??protected????????????????????????????????????public?????
??????1???????public??????????????????public???
??????2???????е?protected??????????????????protected???
??????3???????е?private????????????в???????
????2.???protected???????????????????????????public??protected?????????????????????????????????????????????????????????????г??????????????????е?public??protected???????
??????1???????public????????????б??protected?????
??????2???????protected??????????????????protected?????
??????3???????е?private????????????в???????
????3.???private???????????????????????????public??protected?????????????????????????????????????????????????????????????г??????????????????е?public??protected???????
??????1???????public????????????б??private?????
??????2???????protected????????????б??private?????
??????3???????private????????????в???????
???????????????????????????????????????????????
?????? ?? ?? ? ?????public??? ?????protected??? ?????private??? public???? ????public??? ???protected??? ????? protected???? ???protected??? ????protected??? ????? private???? ???private??? ???private??? ?????
??????????????????
????#include <iostream>
????class Base {
????public:
????int public_a;
????virtual void test() = 0;
????protected:
????int protected_a;
????private:
????int private_a;
????};
????//???м??
????class PublicDerived : public Base {
????public:
????virtual void test() {
????public_a = 1; //public_a public??к???public????
????protected_a = 2; //protected_a ????protected????
????//private_a = 3; //????????????????г??
????}
????};
????//???????
????class ProtectedDerived : protected Base {
????public:
????virtual void test() {
????public_a = 1; //public_a protected??к???protected????
????protected_a = 2; //protected_a ????protected????
????//private_a = 3; //????????????????г??
????}
????};
????//??м??
????class PrivateDerived : private Base {
????public:
????virtual void test() {
????public_a = 1; //public_a private??к???private????
????protected_a = 2; //protected_a private??к???private????
????//private_a = 3; //????????????????г??
????}
????};
??????c++??public?????is-a??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11