亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么“~ChildLabourer”改為“~childLabourer”才可通過

為什么要把“~ChildLabourer”改為“~childLabourer”才可通過????????????不應該和類同名嗎?不應該是大寫嗎??????????????????????????????

正在回答

2 回答

并不是那個原因,你把代碼放到vs里調試調試就知道了

0 回復 有任何疑惑可以回復我~

我的沒改就通過了,就是和類名同名,提示的應該是錯誤的,我的是其他方面的錯誤也是提示析構函數錯誤應小寫,

如下為能運行的代碼

代碼如下

#include <iostream>

#include <stdlib.h>

#include <string>

using namespace std;

/**

?* 定義工人類: Worker

?* 數據成員: m_strName

?* 成員函數: work()

?*/

class Worker

{

public:

? ? Worker(string name)

{

m_strName = name;

cout << "Worker" << endl;

}

~Worker()

{

cout << "~Worker" << endl;

}

void work()

{

cout << m_strName << endl;

cout << "work" << endl;

}

protected:

string m_strName;

};


/**

?* 定義兒童類: Children

?* 數據成員: m_iAge

?* 成員函數: play()

?*/

class Children

{

public:

Children(int age)

{

m_iAge = age;

cout << "Children" << endl;

}

~Children()

{

cout << "~Children" << endl;

}

void play()

{

cout << m_iAge << endl;

cout << "play" << endl;

}

protected:

int m_iAge;

};


/**

?* 定義童工類: ChildLabourer

?* 公有繼承工人類和兒童類

?*/

class ChildLabourer : public Worker,public Children

{

public:

ChildLabourer(string name, int age):Worker(name),Children(age)

{

cout << "ChildLabourer" << endl;

}


~ChildLabourer()

{

cout << "~ChildLabourer" << endl;

}

};


int main(void)

{

? ? // 使用new關鍵字創建童工類對象

ChildLabourer *p=new ChildLabourer("workerss",19);

? ? // 通過童工對象調用父類的work()和play()方法

p->work();

? ? p->play();

? ? // 釋放

? ? delete p;

? ? p=NULL;


return 0;

}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
C++遠征之繼承篇
  • 參與學習       75192    人
  • 解答問題       251    個

繼承,C++面向對象三大特征之一,通過編碼實踐方式講解到操作層面

進入課程

為什么“~ChildLabourer”改為“~childLabourer”才可通過

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號