class A
{
private:
int m_nValue;
public:
A()
{
m_nValue = 0;
}
A(int nValue)
{
m_nValue = nValue);
~A()
{}
}
現在主如果我叫動態內存分配使用默認值
A a(2);// 2 will be assigned for m_nValue of object A.
現在我們該怎麼做,如果我要定義對象的數組。 此外,我們如何做到這一點,如果我使用new運算符 像
A *pA;
pA = new A[5];// while creating the object i want the parameterised constructor to be
//called
我希望這個問題是清楚的動態創建的對象。請讓我知道是否需要更多解釋
更多「好奇心」?或者更多沒有準備閱讀C++教科書? – 2010-06-10 17:19:30
只是「好奇心」。 – ckv 2010-06-10 17:21:11
那麼你在哪些C++教科書中使用了這個問題沒有涉及? – 2010-06-10 17:23:30