1.友元函数
2.友元类
3.继承(公有继承)
4.公有继承的访问权限
5.私有继承的访问权限
6.保护继承的访问权限(两次继承)
==友元函数== #includeusing namespace std; class love { public: love(int you,int me); friend int baby(love& );//################ private: int Me; int You; }; love::love(int you,int me) { You = you; Me = me; } int baby(love& refnum) { return refnum.You + refnum.Me ;//########### } int main() { love aini(500,21); cout<<"我想对你说:"< ==友元类== #includeusing namespace std; class Date; //声明Date类 class Time //定义Time类,描述时分秒 { public: Time(int con_hour, int con_minute, int con_second) //定义构造函数 { m_nHour = con_hour; m_nMinute = con_minute; m_nSecond = con_second; } friend class Date; //声明Date为Time的友元类 private: int m_nHour, m_nMinute, m_nSecond; }; class Date //定义Date类 { public: Date(int con_year, int con_month, int con_day)//定义构造函数 { m_nYear = con_year; m_nMonth = con_month; m_nDay = con_day; } void display_date_time(Time &ref_time); //声明display_date_time()函数 private: int m_nYear, m_nMonth, m_nDay; }; void Date::display_date_time(Time &ref_time) { cout << m_nYear << "-" << m_nMonth << "-" << m_nDay << " " << ref_time.m_nHour << ":" << ref_time.m_nMinute//################ << ":" << ref_time.m_nSecond << endl; //############### } int main() { Time time(17, 30, 20); //定义Time对象 Date date(2017, 2, 23); //定义Date对象 date.display_date_time(time); //显示年月日、时分秒信息 return 0; } ==继承(公有继承)== #include#include using namespace std; class Animal { public: void speak() { cout<<"animal language."< ==公有继承的访问权限== #include#include using namespace std; class Animal { public: void set_weight(int weight){m_Weight = weight;} int get_weight(){return m_Weight;} void set_age(int age){m_Age = age;} protected: int m_Age; //protected成员可以被派生类访问 private: int m_Weight; //私有成员被派生类不可访问 }; class Dog:public Animal { public: Dog (string con_name):m_Name(con_name){} void print_age(){ cout< ==私有继承的访问权限== //把从基类继承的protected、public成员当做私有成员,主函数不能直接访问基类的成员 #include#include using namespace std; class Animal { public: void set_weight(int weight){m_Weight = weight;} int get_weight(){return m_Weight;} void set_age(int age){ m_Age = age; } protected: int m_Age; private: int m_Weight; }; class Dog:private Animal { public: Dog(string con_name):m_Name(con_name){} void set_print_weight() { set_weight(6); //################ cout< ==保护继承的访问权限(多重继承:类Animal——>次类Dog——>再次类Dog_plus)== //把从基类继承的protected、public成员当做保护成员 #include#include #include using namespace std; class Animal { public: void set_weight(int weight){m_Weight = weight;} int get_weight(){return m_Weight;} void set_age(int age){m_Age = age;} protected: int m_Age; private: int m_Weight; }; class Dog:protected Animal //################# { public: Dog(string con_name):m_Name(con_name){} void set_print_weight() { set_weight(8); cout<



