C++-类的理解

来源:互联网 发布:网络机顶盒怎么设置 编辑:程序博客网 时间:2024/05/21 06:23


#include<iostream>using namespace std;class M{protected:int m;public:void get_m(int);};class N{protected:int n;public:void get_n(int);};class P:public M, public N  //多重继承{public:void display(void);};void M::get_m(int x){ m=x; }void N::get_n(int y){ n=y; }void P::display(){  cout<<"m= "<<m<<endl;   cout<<"n= "<<n<<endl;   cout<<"m*n= "<<m*n<<endl;}int main(){   P p;   p.get_m(10);   p.get_n(20);   p.display();   int m=0;   getchar();   return 0;}






0 0
原创粉丝点击