精華區beta Programming 關於我們 聯絡資訊
我不太瞭解 CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0): m_Length(lv), m_Breadth(bv), m_Height(hv) { cout << endl << "Constructor called."; } 建構子這裡的宣告是代表什麼? 因為lv=1.0 後面又有m_Length(lv) 那我的lv值到哪裡去呢? 附上原始碼,謝謝! #include <iostream> using namespace std; class CBox { public: CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0): m_Length(lv), m_Breadth(bv), m_Height(hv) { cout << endl << "Constructor called."; } double Volume() { return m_Length*m_Breadth*m_Height; } private: double m_Length; double m_Breadth; double m_Height; }; int main() { CBox match(2.2, 1.1, 0.5); CBox box2; cout << endl << "Volume of match = " << match.Volume(); // box2.m_Length = 4.0; cout << endl << "Volume of box2 = " << box2.Volume(); cout << endl; system("PAUSE"); return 0; } -- ┌─────KKCITY─────┐─┐ 優質連線服務///!! bbs.kkcity.com.tw └─ KKADSL 帶你環遊全世界 └──From:140.109.139.91 ──┘ KKADSL http://adsl.kkcity.com.tw --