C++类 实例 数据成员 成员函数 构造函数 析构函数

来源:互联网 发布:最美的古诗词知乎 编辑:程序博客网 时间:2024/06/05 02:37

class student {

       //不写权限默认为私有的 private

       int   id;

       char name[16];

       int age;

       int sex;


public:

         int grade;

         int class;

protect:

        int aihao;


public:

       void sayhello{

           printf("hello");

      };

     void sayhello2();   //可以把声明写再类内,实现写在外部

     

};  //要以分号结尾


   student类sayhello2的实现

   void student::sayhello2(){

       printf("hello2");

  };


student xiaoming;

xiaoimng.sayhello();  







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