#include<iostream.h>
class test{
int a;
char b;
public:
test()
{
cout<<"\n\nDefault constructor being called";
}
test(int i,char j)
{
a=i;
b=j;
cout<<"\n\nConstructor with arguments called";
}
};
int main()
{
test tarray[5];
test newobj(31,'z');
};
在上面的代碼片段中,我們可以初始化值爲tarray[5]
?一類對象數組
當然,您初始化的元素將調用相應的構造函數,而未初始化的元素將通過默認構造函數實例化。 – 2010-05-31 06:52:03