【1701H1】【穆晨】【171109】连续第三十天总结

来源:互联网 发布:全面战争mac 迅雷下载 编辑:程序博客网 时间:2024/06/06 18:33

任务:类和对象

class 类名{

public:

          公有成员列表;

protected:

          保护成员列表;

private:

          私有成员列表;

};

不要忘了‘;’。

class AA{

          int a=20     //不能在类的定义过程中给其成员赋值

public:

          void set(int a);

         void print();

};

类体内说明成员函数的一般格式:

函数类型 成员函数名(形参列表);

类体外定义成员函数的一般格式:

函数类型 类名::成员函数名(形参列表)

函数体

class A{

    int a,b;

protected:

   int c;

public:

   int d;

  void set(int,int,int);

  void print();

};

void A::set(int m,int n, int k)

{

     a=m;

     b=n;

     c=m+n;

    d=k;

}

void A::print(){cout<<a<<'\t'<<b<<'\t<<c<<'\t'<<d<<endl;}'


阅读全文
0 0
原创粉丝点击