2017-05-22 32 views

回答

4

是否有可能有在C以上的參數化的構造++?

是的。

例如爲:

class square 
{ 
    int m_top; 
    int m_left; 
    int m_right; 
    int m_bottom; 
public: 
    // Constructor for case when all data is provided 
    square(int top, int left, int right, int bottom) : m_top(top), m_left(left), m_right(right), m_bottom(bottom) 
    { 
    } 
    // Constructor for case when some data is missing 
    square(int top, int left) : m_top(top), m_left(left), m_right(top+1), m_bottom(left+1) 
    { 
    } 
    // ... other members (like default constructor, getters, setters, etc.) 
}; 

,並有可能與參數的析構函數?

您可以找到有關destrtuctor in C++ reference一些選項,但名稱和簽名(參數)不在選項。

相關問題