<2017年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

C++类 单冒号

1.继承

class Base { };

class Derived : public Base { };

示列:

  class Base
  {
   public:
   int a=10;
  };

  class Derived : public Base
  {

  };

  int main()
  {
   Derived b;
   cout<<b.a<<endl;
  }

 


2.访问控制

class MyClass {
public:
    void public_member() { }
private:
    void private_member() { }
};

 


3.列表初始化

class MyClass {
private:
    int member;
public:
    MyClass() : member(0) { }
};

 


4.位域

class MyClass {
public:
    unsigned first : 1;
    unsigned second : 2;
    unsigned third : 4;
};

posted @ 2018-01-03 16:09  史D芬周  阅读(1849)  评论(0编辑  收藏  举报