為什么“~ChildLabourer”改為“~childLabourer”才可通過
為什么要把“~ChildLabourer”改為“~childLabourer”才可通過????????????不應該和類同名嗎?不應該是大寫嗎??????????????????????????????
為什么要把“~ChildLabourer”改為“~childLabourer”才可通過????????????不應該和類同名嗎?不應該是大寫嗎??????????????????????????????
2016-06-20
舉報
2016-08-01
并不是那個原因,你把代碼放到vs里調試調試就知道了
2016-06-20
我的沒改就通過了,就是和類名同名,提示的應該是錯誤的,我的是其他方面的錯誤也是提示析構函數錯誤應小寫,
如下為能運行的代碼
#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;
}