5-1
C++ Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <iostream>
#include <string> #include "myhead.h" #include <cstdio> using namespace std ; class sharp { public: string a; protected: string b; private: string c; public: sharp()//这里必须是public { //this->inital(); this->a="public:"; this->b ="protected:"; this->c ="private:"; } }; int main(void) { sharp check; cout<<check.a; cout<<check.b; check<<check.c; system("pause"); } |
5-3
5-4
5-6
C++ Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <iostream>
using namespace std; class hen { public: class next { public: class egg { public: void dispaly(void) { cout<<"egg"<<endl; } }; void dispaly(void) { cout<<"next"<<endl; } }; void dispaly(void) { cout<<"hen"<<endl; } }; void main(void) { //类的嵌套 hen dage; //二级嵌套 hen::next jidan; //三级嵌套 hen::next::egg fuck; dage.dispaly(); jidan.dispaly(); fuck.dispaly(); system("pause"); } |