阅读程序

来源:互联网 发布:mysql 组合主键关联 编辑:程序博客网 时间:2024/05/17 06:47
#include <iostream>using namespace std;class base{private:    int m;public:    base() {};    base(int m){this->m=m;}   int get(){return m;}    void set(int m){this->m=m;}};//base_endint main(){    base *ptr;    ptr=new base[2];    ptr->set(30);    ptr=ptr+1;    ptr->set(50);    base a[2]= {1,9};    cout<<a[0].get()<<","<<a[1].get()<<endl;    cout<<ptr->get()<<",";    ptr=ptr-1;    cout<<ptr->get()<<endl;    delete[] ptr;    return 0;}


1,9

50,30

#include<iostream>
using namespace std;
class CE
{
private:
    int a,b;
    int getmin(){return (a<b? a:b);}
public:
    int c;
    void SetValue(int x1,int x2, int x3)
    {
        a=x1;
        b=x2;
        c=x3;
    }
    int GetMin();
};

int CE::GetMin()
{
    int d=getmin();
    return (d<c? d:c);
}

int main()
   {

    int x=5,y=12,z=8;
    CE *ep;
    ep=new CE;
    ep->SetValue(x+y,y-z,10);
    cout<<ep->GetMin()<<endl;
    CE a=*ep;
    cout<<a.GetMin()*3+15<<endl;
    return 0;
}

4 27

0 0