奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

C語言

C++類中的繼承實例詳解

時間:2024-07-05 12:37:40 C語言 我要投稿
  • 相關(guān)推薦

C++類中的繼承實例詳解

  類的繼承,是新的類從已有類那里得到已有的特性;驈囊延蓄惍a(chǎn)生新類的過程就是類的派生。下面是小編分享的C++類中的繼承實例詳解,一起來看一下吧。

  實例效果:


  實現(xiàn)代碼:

  #include<iostream>

  #include<string>

  using namespace std;

  class Person

  {

  public:

  Person(const char* name = "abc")

  :_name(name)

  {

  cout << "Person()" << endl;

  }

  Person(const Person& pp)

  :_name(pp._name)

  {

  cout << "Person(const Person&)" << endl;

  }

  Person& operator=(const Person& pp)

  {

  cout << "Person& operator=(const Person&)" << endl;

  if (this != &pp)

  {

  _name = pp._name;

  }

  return *this;

  }

  ~Person()

  {

  cout << "~Person()" << endl;

  }

  protected:

  string _name;

  };

  class Student :public Person

  {

  public:

  Student(const char* name, int num)

  :Person(name)

  , _num(num)

  {

  cout << "Student()" << endl;

  }

  Student(const Student& A)

  :Person(A)

  , _num(A._num)

  {

  cout << "Student(const Student& A)" << endl;

  }

  Student& operator=(const Student& A)

  {

  cout << "Student& operator=(const Student& A)" << endl;

  if (this != &A)

  {

  Person::operator=(A);

  _num = A._num;

  }

  return *this;

  }

  ~Student()

  {

  cout << "~Student()" << endl;

  }

  private:

  int _num;

  };

  void test()

  {

  Student a1("peter", 20);

  Student a2(a1);

  a2 = a1;

  }

  int main()

  {

  test();

  return 0;

  }


【C++類中的繼承實例詳解】相關(guān)文章:

c++快速排序詳解10-18

Java實現(xiàn)多繼承的實例07-18

C++類的轉(zhuǎn)換10-17

C與C++之間相互調(diào)用的實例07-07

Java實現(xiàn)在不同線程中運(yùn)行的代碼實例詳解06-11

Java內(nèi)部類詳解及實例分析06-25

C語言循環(huán)隊列的表示與實例詳解08-21

C語言合并排序及實例代碼詳解11-02

java繼承抽象類07-28

Java中的Spring入門實例09-15

主站蜘蛛池模板: 宽城| 视频| 喀喇| 都昌县| 金华市| 永吉县| 安乡县| 安国市| 大余县| 新兴县| 金华市| 明溪县| 元阳县| 乌海市| 诸暨市| 上饶市| 梁平县| 长武县| 大名县| 东光县| 长丰县| 福州市| 兴安县| 宜章县| 衡东县| 伊川县| 肥东县| 两当县| 龙游县| 通州区| 塔城市| 横山县| 砚山县| 广水市| 惠安县| 德令哈市| 贵德县| 贡嘎县| 新兴县| 林甸县| 保亭|