成員函數(shù)里有const類型時(shí),拷貝構(gòu)造函數(shù)該怎么定義???
private:
string m_strName;
int m_iAge;
const int m_iMax;
};
Teatcher::Teatcher (const Teatcher &)?
{
cout << "Teatcher (const Teatcher &tea)" << endl;
}
報(bào)錯(cuò)如下:
2 IntelliSense: ?"Teatcher::Teatcher(const Teatcher &)" 未提供初始值設(shè)定項(xiàng):?
? ? ? ? ? ? 常量 成員 "Teatcher::m_iMax" d:\VCcodes\learn_c++\learn_c++\Teacher.cpp 14 1 learn_c++
2016-08-08
Teatcher::Teatcher (const Teatcher &tea):m_iMax(20)
{
}?
這樣就行了
2016-08-07
不管用,比如加了個(gè)t,但是如果我把const int m_iMax;這個(gè)成員函數(shù)的聲明和定義都去掉,就不會(huì)出現(xiàn)這個(gè)錯(cuò)誤,所以應(yīng)該是因?yàn)閺腸onst類型的成員函數(shù)的關(guān)系
2016-08-07
Teatcher::Teatcher (const Teatcher &“這里加一個(gè)形參”)?