#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 c开发者_如何学JAVAalled";
}
};
int main()
{
test tarray[5];
test newobj(31,'z');
};
In the above code snippet can we initialize values to tarray[5]
?
test tarray[5] = {test(1, 2), test(), test(5, 6), test()};
The fifth element will be initialized with default constructor.
//here length of array will be inferred from number of initializers,
// so it's going to be 4
test tarray[] = {test(1, 'a'), test(), test(5, 'b'), test()};
精彩评论